From 0ee777c5923ef5a408c314b13edafed0521c136e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Wed, 17 Mar 2021 10:01:05 +0100 Subject: [PATCH 1/3] Improve README Basically going through all of it. --- README.md | 76 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 41 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index f81947f..3273c5d 100644 --- a/README.md +++ b/README.md @@ -1,42 +1,48 @@ -[![Build Status](https://travis-ci.org/A5hleyRich/wp-queue.svg?branch=master)](https://travis-ci.org/A5hleyRich/wp-queue) +# WP Queue + +[![Build Status](https://travis-ci.org/deliciousbrains/wp-queue.svg?branch=master)](https://travis-ci.org/github/deliciousbrains/wp-queue) [![Code Coverage](https://scrutinizer-ci.com/g/A5hleyRich/wp-queue/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/A5hleyRich/wp-queue/?branch=master) -[![Total Downloads](https://poser.pugx.org/a5hleyrich/wp-queue/downloads)](https://packagist.org/packages/a5hleyrich/wp-queue) +[![Total Downloads](https://poser.pugx.org/a5hleyrich/wp-queue/downloads)](https://packagist.org/packages/a5hleyrich/wp-queue/stats) [![Latest Stable Version](https://poser.pugx.org/a5hleyrich/wp-queue/v/stable)](https://packagist.org/packages/a5hleyrich/wp-queue) -[![License](https://poser.pugx.org/a5hleyrich/wp-queue/license)](https://packagist.org/packages/a5hleyrich/wp-queue) +[![License](https://poser.pugx.org/a5hleyrich/wp-queue/license)](https://github.com/deliciousbrains/wp-queue/blob/master/LICENSE.md) + +Job queues for WordPress. -## Prerequisites +### Prerequisites -WP_Queue requires PHP __5.3+__. +WP Queue requires PHP 5.3+. The following database tables need to be created: -``` +```sql CREATE TABLE {$wpdb->prefix}queue_jobs ( -id bigint(20) NOT NULL AUTO_INCREMENT, -job longtext NOT NULL, -attempts tinyint(3) NOT NULL DEFAULT 0, -reserved_at datetime DEFAULT NULL, -available_at datetime NOT NULL, -created_at datetime NOT NULL, -PRIMARY KEY (id) + id bigint(20) NOT NULL AUTO_INCREMENT, + job longtext NOT NULL, + attempts tinyint(3) NOT NULL DEFAULT 0, + reserved_at datetime DEFAULT NULL, + available_at datetime NOT NULL, + created_at datetime NOT NULL, + PRIMARY KEY (id) +); ``` ``` CREATE TABLE {$wpdb->prefix}queue_failures ( -id bigint(20) NOT NULL AUTO_INCREMENT, -job longtext NOT NULL, -error text DEFAULT NULL, -failed_at datetime NOT NULL, -PRIMARY KEY (id) + id bigint(20) NOT NULL AUTO_INCREMENT, + job longtext NOT NULL, + error text DEFAULT NULL, + failed_at datetime NOT NULL, + PRIMARY KEY (id) +); ``` Alternatively, you can call the `wp_queue_install_tables()` helper function to install the tables. If using WP_Queue in a plugin you may opt to call the helper from within your `register_activation_hook`. -## Jobs +### Jobs Job classes should extend the `WP_Queue\Job` class and normally only contain a `handle` method which is called when the job is processed by the queue worker. Any data required by the job should be passed to the constructor and assigned to a public property. This data will remain available once the job is retrieved from the queue. Let's look at an example job class: -``` +```php push( new Subscribe_User_Job( 12345 ) ); ``` -You can create delayed jobs by passing an optional second parameter to the `push` method. This job will be delayed by 60 minutes: +You can create delayed jobs by passing an optional second parameter to the `push` method. This job will be delayed by 60 minutes. -``` +```php wp_queue()->push( new Subscribe_User_Job( 12345 ), 3600 ); ``` -## Cron Worker +### Cron Worker -Jobs need to be processed by a queue worker. You can start a cron worker like so, which piggy backs onto WP cron: +Jobs need to be processed by a queue worker. You can start a cron worker like so, which piggy backs onto WP cron. -``` +```php wp_queue()->cron(); ``` You can also specify the number of times a job should be attempted before being marked as a failure. -``` +```php wp_queue()->cron( 3 ); ``` -## Local Development +### Local Development -When developing locally you may want jobs processed instantly, instead of them being pushed to the queue. This can be useful for debugging jobs via Xdebug. Add the following filter to use the `sync` connection: +When developing locally you may want jobs processed instantly, instead of them being pushed to the queue. This can be useful for debugging jobs via Xdebug. Add the following filter to use the `sync` connection. -``` -add_filter( ‘wp_queue_default_connection’, function() { - return ‘sync’; +```php +add_filter( 'wp_queue_default_connection', function () { + return 'sync'; } ); ``` -## License +### License -WP Queue is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT). \ No newline at end of file +WP Queue is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT). From 44d88149ba7df2306d3b2630fa19077174cea83a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Wed, 17 Mar 2021 10:03:15 +0100 Subject: [PATCH 2/3] Add syntax highlighting to README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3273c5d..8ffea95 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ CREATE TABLE {$wpdb->prefix}queue_jobs ( ); ``` -``` +```sql CREATE TABLE {$wpdb->prefix}queue_failures ( id bigint(20) NOT NULL AUTO_INCREMENT, job longtext NOT NULL, From 778d9a2f6294ea8e74154c3585c1a42cc938d107 Mon Sep 17 00:00:00 2001 From: "Ian M. Jones" Date: Fri, 2 Feb 2024 15:31:25 +0000 Subject: [PATCH 3/3] Merge in changes from master --- README.md | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 8ffea95..2825211 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,14 @@ # WP Queue -[![Build Status](https://travis-ci.org/deliciousbrains/wp-queue.svg?branch=master)](https://travis-ci.org/github/deliciousbrains/wp-queue) -[![Code Coverage](https://scrutinizer-ci.com/g/A5hleyRich/wp-queue/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/A5hleyRich/wp-queue/?branch=master) -[![Total Downloads](https://poser.pugx.org/a5hleyrich/wp-queue/downloads)](https://packagist.org/packages/a5hleyrich/wp-queue/stats) -[![Latest Stable Version](https://poser.pugx.org/a5hleyrich/wp-queue/v/stable)](https://packagist.org/packages/a5hleyrich/wp-queue) -[![License](https://poser.pugx.org/a5hleyrich/wp-queue/license)](https://github.com/deliciousbrains/wp-queue/blob/master/LICENSE.md) +[![Total Downloads](https://poser.pugx.org/deliciousbrains/wp-queue/downloads)](https://packagist.org/packages/deliciousbrains/wp-queue) +[![Latest Stable Version](https://poser.pugx.org/deliciousbrains/wp-queue/v/stable)](https://packagist.org/packages/deliciousbrains/wp-queue) +[![License](https://poser.pugx.org/deliciousbrains/wp-queue/license)](https://packagist.org/packages/deliciousbrains/wp-queue) Job queues for WordPress. -### Prerequisites +## Prerequisites -WP Queue requires PHP 5.3+. +WP_Queue requires PHP __7.3+__. The following database tables need to be created: @@ -38,7 +36,7 @@ CREATE TABLE {$wpdb->prefix}queue_failures ( Alternatively, you can call the `wp_queue_install_tables()` helper function to install the tables. If using WP_Queue in a plugin you may opt to call the helper from within your `register_activation_hook`. -### Jobs +## Jobs Job classes should extend the `WP_Queue\Job` class and normally only contain a `handle` method which is called when the job is processed by the queue worker. Any data required by the job should be passed to the constructor and assigned to a public property. This data will remain available once the job is retrieved from the queue. Let's look at an example job class: @@ -68,14 +66,14 @@ class Subscribe_User_Job extends Job { */ public function handle() { $user = get_user_by( 'ID', $this->user_id ); - + // Process the user... } } ``` -### Dispatching Jobs +## Dispatching Jobs Jobs can be pushed to the queue like so: @@ -83,15 +81,15 @@ Jobs can be pushed to the queue like so: wp_queue()->push( new Subscribe_User_Job( 12345 ) ); ``` -You can create delayed jobs by passing an optional second parameter to the `push` method. This job will be delayed by 60 minutes. +You can create delayed jobs by passing an optional second parameter to the `push` method. This job will be delayed by 60 minutes: ```php wp_queue()->push( new Subscribe_User_Job( 12345 ), 3600 ); ``` -### Cron Worker +## Cron Worker -Jobs need to be processed by a queue worker. You can start a cron worker like so, which piggy backs onto WP cron. +Jobs need to be processed by a queue worker. You can start a cron worker like so, which piggy backs onto WP cron: ```php wp_queue()->cron(); @@ -103,16 +101,16 @@ You can also specify the number of times a job should be attempted before being wp_queue()->cron( 3 ); ``` -### Local Development +## Local Development When developing locally you may want jobs processed instantly, instead of them being pushed to the queue. This can be useful for debugging jobs via Xdebug. Add the following filter to use the `sync` connection. ```php -add_filter( 'wp_queue_default_connection', function () { +add_filter( 'wp_queue_default_connection', function() { return 'sync'; } ); ``` -### License +## License WP Queue is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).