-
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?
Changes from all commits
5bb5d6d
6ee4163
783e27f
da54e5f
38d040e
9d498ab
27d6d0d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Give\Framework\Migrations\Contracts; | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
interface BatchMigration | ||
{ | ||
/** | ||
* @unreleased | ||
* | ||
* Get the number of items per batch | ||
*/ | ||
public function getBatchSize(): int; | ||
|
||
/** | ||
* @unreleased | ||
* | ||
* Get the total items count | ||
*/ | ||
public function getItemsCount(): int; | ||
|
||
/** | ||
* @unreleased | ||
* | ||
* Run batch | ||
*/ | ||
public function runBatch($batchNumber); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,8 @@ public function boot() | |
{ | ||
Hooks::addAction('admin_init', ManualMigration::class, '__invoke', 0); | ||
Hooks::addAction('admin_init', MigrationsRunner::class, 'run', 0); | ||
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 | ||
Comment on lines
-33
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
Hooks::addAction('action_scheduler_init', MigrationsRunner::class, 'run'); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,25 @@ public function enqueueAsyncAction( | |
} | ||
} | ||
|
||
/** | ||
* @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]; | ||
} | ||
Comment on lines
+45
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
/** | ||
* @since 3.6.0 | ||
* | ||
|
@@ -76,14 +95,15 @@ public function getActionByHookArgsGroup( | |
|
||
/** | ||
* @since 3.6.0 | ||
* @unreleased - switch parameter $status position with $returnFormat position | ||
* | ||
* @param string $group The group to assign this job to. | ||
* @param string $returnFormat OBJECT, ARRAY_A, or ids. | ||
* @param string $status ActionScheduler_Store::STATUS_COMPLETE or ActionScheduler_Store::STATUS_PENDING | ||
* | ||
* @return array | ||
*/ | ||
public function getActionsByGroup(string $group, string $returnFormat = OBJECT, string $status = ''): array | ||
public function getActionsByGroup(string $group, string $status = '', string $returnFormat = OBJECT): array | ||
{ | ||
$args = [ | ||
'group' => $group, | ||
|
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.