Created
July 7, 2019 02:28
-
-
Save mglaman/6f5b0b2194d2f5ec7f1a40d00dd5ca6c to your computer and use it in GitHub Desktop.
ReactPHP Drupal Tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php declare(strict_types=1); | |
require __DIR__ . '/../vendor/autoload.php'; | |
function run_command(string $command): void { | |
$loop = React\EventLoop\Factory::create(); | |
$process = new React\ChildProcess\Process($command); | |
$process->start($loop); | |
$process->on('exit', function ($exitCode) use ($command) { | |
// Trigger alerts that the command finished. | |
}); | |
$process->stdout->on('data', function ($chunk) { | |
// Optinally log the output. | |
}); | |
$process->stdout->on('error', function (Exception $e) use ($command) { | |
// Log an error. | |
}); | |
$process->stderr->on('data', function ($chunk) use ($command) { | |
if (!empty(trim($chunk))) { | |
// Log output from stderr | |
} | |
}); | |
$process->stderr->on('error', function (Exception $e) use ($command) { | |
// Log an error. | |
}); | |
$loop->run(); | |
} | |
$loop = React\EventLoop\Factory::create(); | |
// Run cron every twenty minutes. | |
$loop->addPeriodicTimer(1200, function () { | |
run_command('drush cron'); | |
}); | |
// Every thirty seconds, process jobs from queue1 | |
$loop->addPeriodicTimer(30, function () { | |
run_command(sprintf('drush advancedqueue:queue:process queue1')); | |
}); | |
// Every two minutes, process jobs from queue2 | |
$loop->addPeriodicTimer(120, function () { | |
run_command(sprintf('drush advancedqueue:queue:process queue2')); | |
}); | |
$loop->run(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$autoloader = require __DIR__ . '/../vendor/autoload.php'; | |
$request = Symfony\Component\HttpFoundation\Request::createFromGlobals(); | |
$request->attributes->set( | |
Symfony\Cmf\Component\Routing\RouteObjectInterface::ROUTE_OBJECT, | |
new Symfony\Component\Routing\Route('<none>') | |
); | |
$request->attributes->set( | |
Symfony\Cmf\Component\Routing\RouteObjectInterface::ROUTE_NAME, | |
'<none>' | |
); | |
$kernel = new Drupal\Core\DrupalKernel('prod', $autoloader); | |
$kernel::bootEnvironment(); | |
$kernel->setSitePath('sites/default'); | |
Drupal\Core\Site\Settings::initialize($kernel->getAppRoot(), $kernel->getSitePath(), $autoloader); | |
$kernel->boot(); | |
$kernel->preHandle($request); | |
$loop = React\EventLoop\Factory::create(); | |
$loop->addPeriodicTimer(10, function () { | |
$cron = \Drupal::service('cron'); | |
$cron->run(); | |
}); | |
$loop->run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment