-
Notifications
You must be signed in to change notification settings - Fork 195
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
Feature: Add support for running migration in batches #7755
base: epic/campaigns
Are you sure you want to change the base?
Conversation
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.
Love the start, @alaca! A couple thoughts:
- I really want to use interfaces, but we're going to run into issues because we really should be using inheritance to for sync and async migrations, but interfaces can't enforce static methods until PHP 7.4.
- So for now, let's:
- make a
BaseMigration
abstract class with the staticid()
andtimestamp()
methods - Change
BatchMigration
to an abstract class that extends this - Extend the
Migration
class with this - Use
BaseMigration
in the migrations runner and registrar
- make a
- We still want batch migrations to hold up the queue, as all migrations need to run in order, regardless of what kind of migration they are
Love seeing this! So cool!
abstract public function run(); | ||
public function run() | ||
{ | ||
if ( ! is_subclass_of($this, BatchMigration::class)) { | ||
throw new RuntimeException('run method is not defined.'); | ||
} | ||
} |
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.
Let's avoid this if we can. This sort of thing can't be caught by static analysis, so the only way to know if there's an issue is at runtime.
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.
If we switch everything to inheritance we shouldn't need to do this.
/** | ||
* @unreleased | ||
*/ | ||
public function enqueueAction( | ||
int $timestamp, | ||
string $hook, | ||
array $args, | ||
string $group, | ||
bool $unique = false, | ||
int $priority = 10 | ||
): int { | ||
$enqueuedAction = $this->getActionByHookArgsGroup($hook, $args, $group, 'ids'); | ||
if (empty($enqueuedAction)) { | ||
return as_schedule_single_action($timestamp, $hook, $args, $group, $unique, $priority); | ||
} | ||
|
||
return $enqueuedAction[0]; | ||
} |
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.
Please provide a description for this. It looks like it conditionally enqueues a single action so long as that action isn't already queued? We may want to call this safelyEnqueueAction
or something like that.
Hooks::addAction('give_upgrades', MigrationsRunner::class, 'run', 0); | ||
//Hooks::addAction('give_upgrades', MigrationsRunner::class, 'run', 0); | ||
// running batch actions via cron doesn't trigger give_upgrades and all registered actions fail |
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.
Will this break the existing migrations that are using the old upgrade system?
Description
This PR adds support to run migration in batches using Action Scheduler.
Affects
Visuals
Testing Instructions
Pre-review Checklist
@unreleased
tags included in DocBlocks