All Projects → dfmedia → wp-queue-tasks

dfmedia / wp-queue-tasks

Licence: other
Create and process tasks asynchronously in WordPress

Programming Languages

PHP
23972 projects - #3 most used programming language
shell
77523 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to wp-queue-tasks

react-native-dnd-board
A drag and drop Kanban board for React Native.
Stars: ✭ 41 (+141.18%)
Mutual labels:  task
noteboard
📓 Manage your notes & tasks in a tidy and fancy way. A taskbook clone written in Python.
Stars: ✭ 12 (-29.41%)
Mutual labels:  task
tree-core-cpu
A series of RISC-V soft core processor written from scratch. Now, we're using all open-source toolchain( chisel, mill, verilator, NEMU, AM and difftest framework, etc) to design and verify.
Stars: ✭ 22 (+29.41%)
Mutual labels:  processor
qless-php
PHP Bindings for qless
Stars: ✭ 25 (+47.06%)
Mutual labels:  task
nano-staged
Tiny tool to run commands for modified, staged, and committed files in a GIT repository.
Stars: ✭ 347 (+1941.18%)
Mutual labels:  task
fast-laravel
基于Swoole的高性能HTTP服务器,加速您Laravel应用程序。
Stars: ✭ 33 (+94.12%)
Mutual labels:  task
composer
API-first task runner with three methods: task, run and watch.
Stars: ✭ 35 (+105.88%)
Mutual labels:  task
Octavo
Verilog FPGA Parts Library. Old Octavo soft-CPU project.
Stars: ✭ 66 (+288.24%)
Mutual labels:  processor
todo.link
基于项目的任务管理系统
Stars: ✭ 90 (+429.41%)
Mutual labels:  task
croner
Trigger functions and/or evaluate cron expressions in JavaScript. No dependencies. Most features. All environments.
Stars: ✭ 169 (+894.12%)
Mutual labels:  task
AssemblyLine
AssemblyLine is a library for easily writing workflows.
Stars: ✭ 40 (+135.29%)
Mutual labels:  task
csharp-workshop
NDC London 2019, Workshop: Become a better C# programmer: more Value, more Expressions, no Waiting
Stars: ✭ 21 (+23.53%)
Mutual labels:  task
processor
A simple and lightweight JavaScript data processing tool. Live demo:
Stars: ✭ 27 (+58.82%)
Mutual labels:  processor
HexTags
Customize tags & chat colors!
Stars: ✭ 53 (+211.76%)
Mutual labels:  processor
EasyJob
🔨 EasyJob - keep and execute your PowerShell and BAT scripts from one interface
Stars: ✭ 228 (+1241.18%)
Mutual labels:  task
tree-core-ide
The next generation integrated development environment for processor design and verification. It has multi-hardware language support, open source IP management and easy-to-use rtl simulation toolset.
Stars: ✭ 79 (+364.71%)
Mutual labels:  processor
processor
A compiler, assembler, and processor.
Stars: ✭ 24 (+41.18%)
Mutual labels:  processor
YACLib
Yet Another Concurrency Library
Stars: ✭ 193 (+1035.29%)
Mutual labels:  task
lipsi
Lipsi: Probably the Smallest Processor in the World
Stars: ✭ 64 (+276.47%)
Mutual labels:  processor
examples
Taskfiles examples
Stars: ✭ 56 (+229.41%)
Mutual labels:  task

WP Queue Tasks

Build Status codecov

This plugin create's a queue to process tasks. The architecture is pretty straight forward. There is a task post type, where a "task" post gets added to. The task post can be attached to a "queue" which is just a term within the "queues" taxonomy. On every admin shutdown hook, we find all of the queues that need processing, and then post an async request to admin_post for each of the queues, and then process the queue.

The idea of the queue is for it to be a dumb processor that simply recognizes that there are tasks to process. It's up to the callback of the registered queue to do something with the payload.

Registering a queue

To create a new queue, you have to register it with the dfm_register_queue() function. The function accepts two parameters. The first is the $queue_name which is just the string name of the queue. It should be noted that this name should be a slug-friendly name, so it shouln't have any uppercase letters, or spaces. The second parameter that you can pass to this function is the arguments for registering the queue. The arguments that you can pass are outlined below.

  • callback (callable) - The callback function to do something with the actual payload. The function is passed the payload of the task it's supposed to process. required
  • update_interval (int|bool) - The interval at which the queue gets processed. You can pass something like HOUR_IN_SECONDS here, and that well have the queue only be processed once an hour. Default: false
  • minimum_count (int) - The minimum amount of items in the queue before it should be processed.
  • bulk (bool) - Whether or not the queue can handle sending multiple payloads at once. Default: False
  • processor (string) - The type of processor you want to use. The options currently are "async" or "cron". Both of these options technically run the processor async, and share the same processor code. It just allows you some flexibility. The async option posts a small payload to a handler which runs the processor, and the cron option just schedules a cron event to run the processor.
  • retry (int) - The amount of times a retry should be attempted for this particular queue. Default: 3

Using the callback

The callback that is registered with the queue is what actually handles the payload, and does something with it. If the queue supports bulk processing, it will be passed an array of payloads with the ID of the task as the key, and the payload as the value. The callback should either return the ID's of the tasks that should be completed, or false/WP_Error. If false or WP_Error is returned, the tasks will remain in the queue to be processed later, otherwise they will be removed from the queue. It is good to note that if your queue doesn't support bulk processing it doesn't need to return the ID of the task if successful, it can just return something like true.

Code Samples

Simple example of processing a single task at a time, and storing the contents of the task in an option.

wpqt_register_queue( 'my-queue', [
    'callback' => 'sample_callback',
    'processor' => 'cron',
    'retry' => 5,
    'bulk' => false,
] );

wpqt_create_task( 'my-queue', 'sample data' );

function sample_callback( $data, $queue ) {
    $result = update_option( 'my_sample_option_' . $queue, $data );
    return $result;
}

Example of bulk processing some tasks. In this example, we set the minimum count to 10 so we let the queue build up some tasks for us to process in bulk. When setting bulk to true, your processor callback will receive an array of tasks with the key being the ID of the task, and the value being the data stored in the task. To signal the processor that the callback processed a task correctly, you should return the ID of the successfully completed task in an array. See the example below:

wpqt_register_queue( 'my-queue', [
    'callback' => 'sample_callback',
    'bulk' => true,
    'minimum_count' => 10,
] );

$i = 0;
for ( $i < 10; $i++; ) {
    wpgt_create_task( 'my-queue', 'sample data #' . $i );
}

function sample_callback( $data, $queue ) {
    $successful = [];
    if ( ! empty( $data ) && is_array( $data ) {
        foreach ( $data as $id => $payload ) {
            $result = update_option( 'my_sample_option_' . $id, $payload );
            if ( true === $result ) {
                $successful[] = $id;
            }
        }
    }
    return $successful;
}

You can also use the update_interval argument to limit the processor to only running at your set interval. Below is an example of this.

wpqt_register_queue( 'my-queue', [
    'callback' => 'sample_callback',
    'update_interval' => HOUR_IN_SECONDS,
    'bulk' => false,
] );

wpqt_create_task( 'my-queue', 'sample data' );

function sample_callback( $data, $queue ) {
    $result = update_option( 'my_sample_data_' . $queue, $data );
    return $result;
}

Retries

To use the retry system, simply add a retry count when registering your queue. Each queue can have it's own retry limit, and will be tracked independently. Once the maximum retries have been hit, the task will remain in the system, but will be removed from the queue that it hit the limit on, and will be added to a new queue called {$queue_name}_failed so it can be further investigated in the future.

PHP 7.0+

This plugin requires php version 7.0 and up. This is because of the exception handling we are doing for processor callbacks. This is needed so that a callback throwing an error doesn't hold up the entire queue from processing.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].