-
Notifications
You must be signed in to change notification settings - Fork 1
Issue-39: Allow an implementer-provided callback to be executed after each batch (2.x) #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 2.x
Are you sure you want to change the base?
Issue-39: Allow an implementer-provided callback to be executed after each batch (2.x) #49
Conversation
@@ -19,14 +18,13 @@ | |||
* @package alleyinteractive/wp-bulk-task | |||
*/ | |||
class TestCsvBulkTask extends Test_Case { | |||
use Refresh_Database; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Test_Case
already supports this.
'cursor' => $this->cursor, | ||
'min_id' => $this->min_id, | ||
'max_id' => $this->max_id, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cursor is public, but the other two are protected. And they might be needed in the callback. e.g: at every 100 posts, index them in elasticsearch, etc.
array $args, | ||
callable $callable, | ||
string $object_type = 'wp_post', | ||
?callable $after_batch_callback = null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initially, I implemented this at Bulk_Task construct
, but then I changed my mind just because the callback is better together with the run
method.
That however forces one to use the wp_post
object type. I think that's okay, better to be explicit rather than clever here.
Summary
This pull request introduces the ability to allow an implementer-provided callback to be executed after each batch in the
after_batch
function of the bulk task. Fixes #39. Closes #41.Description
The bulk task currently has an
after_batch
function, but it is not pluggable. This enhancement enables implementers to provide their own callbacks to be executed after each batch. The callback can be passed when the bulk task is being set up, allowing greater flexibility and customization. Additionally, several code improvements and updates were made to enhance readability and maintainability.Implementation Details
$after_batch_callback
to theBulk_Task
class to store implementer-provided callbacks.Refresh_Database
trait from various test classes, includingTestPostBulkTask
,TestTermBulkTask
, andTestUserBulkTask
, as database resetting functionality is no longer required or is handled differently.Motivation and Context
This feature was requested to address the need for more customizable post-batch processing in bulk tasks. The context for this need arose from this scenario encountered by Alley developers. This enhancement provides developers with the flexibility to implement their own logic in the
after_batch
process.How Has This Been Tested?
Screenshots (if applicable)
N/A
Types of Changes
Checklist