Added some basic task runner functionality using beanstalkd and the pheanstalk library

This commit is contained in:
2022-10-07 19:17:05 -04:00
parent bb584d5ea0
commit fdb31eeb00
6 changed files with 133 additions and 3 deletions

45
src/runner.php Normal file
View File

@@ -0,0 +1,45 @@
<?php
use Noodlehaus\Config;
use Noodlehaus\Parser\Json;
use Pheanstalk\Pheanstalk;
use BitGoblin\MCST\Runners\RefreshServerDownloads;
require __DIR__ . '/../vendor/autoload.php';
// Load app configuration
$config = Config::load(__DIR__ . '/../conf/defaults.json');
// create pheanstalk object
$pheanstalk = Pheanstalk::create($config->get('beanstalkd.host'), $config->get('beanstalkd.port'));
// we want jobs from 'mcst' tube only.
$pheanstalk->watch('mcst');
while (true) {
echo "Waiting for a new job...\n";
// try to reserve a job
$job = $pheanstalk->reserve();
// check if we actually got a job before trying to do work
if (isset($job)) {
$jobPayload = $job->getData();
switch ($jobPayload) {
case 'refresh-server-downloads':
$rsd = new RefreshServerDownloads($config);
$rsd->start();
break;
default:
echo "Runner command " . $jobPayload . " isn't supported.\n";
break;
}
// remove job
$pheanstalk->delete($job);
}
sleep(60);
}