Skip to content

Commit

Permalink
🚀 Releasing 1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel-James committed Aug 2, 2021
1 parent def1a80 commit cdd700a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
WP Queue Process can be used to fire off non-blocking asynchronous requests or as a background processing tool, allowing you to queue tasks.

* Inspired by [TechCrunch WP Asynchronous Tasks](https://github.com/techcrunch/wp-async-task).
* Forked from [WP Background Processing](https://github.com/deliciousbrains/wp-background-processing).
* Forked from [WP Background Processing](https://github.com/deliciousbrains/wp-background-processing) with few extra options.

__Requires PHP 5.2+__

Expand Down Expand Up @@ -101,11 +101,12 @@ class WP_Example_Process extends \DuckDev\Queue\Task {
* in the next pass through. Or, return false to remove the
* item from the queue.
*
* @param mixed $item Queue item to iterate over
*
* @param mixed $item Queue item to iterate over
* @param string $group Group name of the task (Useful when performing multiple tasks).
*
* @return mixed
*/
protected function task( $item ) {
protected function task( $item, $group ) {
// Actions to perform

return false;
Expand Down Expand Up @@ -155,7 +156,7 @@ foreach ( $items as $item ) {

Save and dispatch the queue:

`$this->example_process->save()->dispatch();`
`$this->example_process->save( 'my-task' ')->dispatch();`

### BasicAuth

Expand Down
24 changes: 17 additions & 7 deletions src/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,24 @@ public function push_to_queue( $data ) {
/**
* Save the process queue.
*
* @param string $group Group name.
*
* @since 1.0.0
* @since 1.0.1 Added group option.
* @access public
*
* @return Task $this
*/
public function save() {
public function save( $group = 'default' ) {
// Generate key.
$key = $this->generate_key();

// Save the data to database.
if ( ! empty( $this->data ) ) {
// Save data.
update_site_option( $key, $this->data );
// Save group name too.
update_site_option( $key . '_group', $group );
}

return $this;
Expand Down Expand Up @@ -175,6 +181,7 @@ public function update( $key, $data ) {
*/
public function delete( $key ) {
delete_site_option( $key );
delete_site_option( $key . '_group' );

return $this;
}
Expand Down Expand Up @@ -375,9 +382,10 @@ protected function get_batch() {
);

// Create new object.
$batch = new stdClass();
$batch->key = $query->$column;
$batch->data = maybe_unserialize( $query->$value_column );
$batch = new stdClass();
$batch->key = $query->$column;
$batch->data = maybe_unserialize( $query->$value_column );
$batch->group = get_site_option( $batch->key . '_group', 'default' );

return $batch;
}
Expand Down Expand Up @@ -406,7 +414,7 @@ protected function handle() {
// Process each item in batch.
foreach ( $batch->data as $key => $value ) {
// Run task.
$task = $this->task( $value );
$task = $this->task( $value, $batch->group );

// If task failed add to queue again.
if ( false !== $task ) {
Expand Down Expand Up @@ -699,12 +707,14 @@ public function cancel_process() {
* in the next pass through. Or, return false to remove the
* item from the queue.
*
* @param mixed $item Queue item to iterate over.
* @param mixed $item Queue item to iterate over.
* @param string $group Group name of the task (Useful when processing multiple tasks).
*
* @since 1.0.0
* @since 1.0.1 Added group option.
* @access protected
*
* @return mixed
*/
abstract protected function task( $item );
abstract protected function task( $item, $group );
}

0 comments on commit cdd700a

Please sign in to comment.