Skip to content

Commit cdd700a

Browse files
committed
🚀 Releasing 1.0.1
1 parent def1a80 commit cdd700a

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

‎README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
WP Queue Process can be used to fire off non-blocking asynchronous requests or as a background processing tool, allowing you to queue tasks.
1010

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

1414
__Requires PHP 5.2+__
1515

@@ -101,11 +101,12 @@ class WP_Example_Process extends \DuckDev\Queue\Task {
101101
* in the next pass through. Or, return false to remove the
102102
* item from the queue.
103103
*
104-
* @param mixed $item Queue item to iterate over
105-
*
104+
* @param mixed $item Queue item to iterate over
105+
* @param string $group Group name of the task (Useful when performing multiple tasks).
106+
*
106107
* @return mixed
107108
*/
108-
protected function task( $item ) {
109+
protected function task( $item, $group ) {
109110
// Actions to perform
110111

111112
return false;
@@ -155,7 +156,7 @@ foreach ( $items as $item ) {
155156

156157
Save and dispatch the queue:
157158

158-
`$this->example_process->save()->dispatch();`
159+
`$this->example_process->save( 'my-task' ')->dispatch();`
159160

160161
### BasicAuth
161162

‎src/Task.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,18 +126,24 @@ public function push_to_queue( $data ) {
126126
/**
127127
* Save the process queue.
128128
*
129+
* @param string $group Group name.
130+
*
129131
* @since 1.0.0
132+
* @since 1.0.1 Added group option.
130133
* @access public
131134
*
132135
* @return Task $this
133136
*/
134-
public function save() {
137+
public function save( $group = 'default' ) {
135138
// Generate key.
136139
$key = $this->generate_key();
137140

138141
// Save the data to database.
139142
if ( ! empty( $this->data ) ) {
143+
// Save data.
140144
update_site_option( $key, $this->data );
145+
// Save group name too.
146+
update_site_option( $key . '_group', $group );
141147
}
142148

143149
return $this;
@@ -175,6 +181,7 @@ public function update( $key, $data ) {
175181
*/
176182
public function delete( $key ) {
177183
delete_site_option( $key );
184+
delete_site_option( $key . '_group' );
178185

179186
return $this;
180187
}
@@ -375,9 +382,10 @@ protected function get_batch() {
375382
);
376383

377384
// Create new object.
378-
$batch = new stdClass();
379-
$batch->key = $query->$column;
380-
$batch->data = maybe_unserialize( $query->$value_column );
385+
$batch = new stdClass();
386+
$batch->key = $query->$column;
387+
$batch->data = maybe_unserialize( $query->$value_column );
388+
$batch->group = get_site_option( $batch->key . '_group', 'default' );
381389

382390
return $batch;
383391
}
@@ -406,7 +414,7 @@ protected function handle() {
406414
// Process each item in batch.
407415
foreach ( $batch->data as $key => $value ) {
408416
// Run task.
409-
$task = $this->task( $value );
417+
$task = $this->task( $value, $batch->group );
410418

411419
// If task failed add to queue again.
412420
if ( false !== $task ) {
@@ -699,12 +707,14 @@ public function cancel_process() {
699707
* in the next pass through. Or, return false to remove the
700708
* item from the queue.
701709
*
702-
* @param mixed $item Queue item to iterate over.
710+
* @param mixed $item Queue item to iterate over.
711+
* @param string $group Group name of the task (Useful when processing multiple tasks).
703712
*
704713
* @since 1.0.0
714+
* @since 1.0.1 Added group option.
705715
* @access protected
706716
*
707717
* @return mixed
708718
*/
709-
abstract protected function task( $item );
719+
abstract protected function task( $item, $group );
710720
}

0 commit comments

Comments
 (0)