Added some basic task runner functionality using beanstalkd and the pheanstalk library
This commit is contained in:
45
src/runner.php
Normal file
45
src/runner.php
Normal 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);
|
||||
}
|
Reference in New Issue
Block a user