Skip to content

Commit

Permalink
Issue #3: Queues are now run sequentially and avoid overlapping runs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ambient-Impact committed Jul 16, 2023
1 parent e005feb commit 90251c8
Showing 1 changed file with 34 additions and 18 deletions.
52 changes: 34 additions & 18 deletions .do/run-background-tasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Omnipedia\BackgroundTasks\WorkerProcess;
use React\EventLoop\Loop;
use React\Promise\ExtendedPromiseInterface;
use function React\Async\series;

require __DIR__ . '/../vendor/autoload.php';

Expand All @@ -20,25 +22,39 @@
(new WorkerProcess('drush cron'))->start();
});

// Every 5 minutes, process jobs from the image style warmer.
$loop->addPeriodicTimer(300, function(): void {
(new WorkerProcess(
'drush queue:process image_style_warmer_pregenerator'
))->start();
});

// Every 10 minutes, enqueue and process the warmer queue.
$loop->addPeriodicTimer(600, function() use ($loop): void {

$loop->futureTick(function(): void {
(new WorkerProcess('drush warmer:enqueue ' . \implode(',', [
'omnipedia_wiki_node_changes',
'omnipedia_wiki_node_cdn',
])))->start();
});
// Every 10 minutes, run queues.
$loop->addPeriodicTimer(600, function(): void {

/** @var boolean Static flag indicating whether a run is currently in progress. */
static $running = false;

if ($running === true) {
return;
}

$running = true;

series([
function(): ExtendedPromiseInterface {
return (new WorkerProcess('drush warmer:enqueue ' . \implode(',', [
'omnipedia_wiki_node_changes',
'omnipedia_wiki_node_cdn',
])))->start()->promise();
},
function(): ExtendedPromiseInterface {
return (new WorkerProcess(
'drush queue:process image_style_warmer_pregenerator'
))->start()->promise();
},
function(): ExtendedPromiseInterface {
return (new WorkerProcess(
'drush queue:process warmer'
))->start()->promise();
},
])->always(function() use (&$running) {

$running = false;

$loop->futureTick(function(): void {
(new WorkerProcess('drush queue:process warmer'))->start();
});

});

0 comments on commit 90251c8

Please sign in to comment.