You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This was already made in the main project, but I found no way to supply this feature in a good way from this queue package. Maybe we could add those classes and the developer simply extends/implements what's needed, since there's no way to reference a task that's outside of the main project files?
tasks/WorkTask.php
<?phpusePhalcon\CLI\Task;
usePhalcon\Queue\DbasDbQueue;
usePhalcon\Text;
usePhalconRest\tasks\traits\Options;
usePhalconRest\tasks\workers\Worker;
classWorkTaskextendsTask
{
useOptions;
protectedstatic$options = [];
protectedstatic$optionsSpec = [
'limit' => '\d+',
'delay' => '[\d\.]+',
];
publicfunction__call($action, array$arguments = [])
{
$name = substr($action, 0, -strlen('action'));
$class = '\PhalconRest\tasks\workers\\'.Text::camelize($name);
if (class_exists($class)) {
$options = self::processOptions(isset($arguments[0])? $arguments[0] : []);
$worker = new$class($options);
if (!($worker instanceof Worker)) {
echo"$class must be an instance of tasks\\workers\\Worker\n";
die(254);
}
$result = (newDbQueue)
->watch($name, true)
->process([$worker,'handleJob'], static::$options['delay']?: 1, static::$options['limit']);
echo"\nStats: ".print_r($result, true);
} else {
echo"There's no such worker class: $name ($class)\n";
die(254);
}
}
publicfunctionmainAction()
{
echo<<<HELP -= DbQueue Task runner =-This scripts walks through available jobs and processes them given a specific class handler.Usage: app/cli.php work «tube»Implementation: tasks/workers/«Tube»::handleJob(\$body, Job \$job):bool|voidOptions: --delay=F Delay between asking for new jobs when the queue is over --limit=I How much jobs to process before exiting --???=??? Other options are passed directly to the Worker constructorHELP;
}
}
Another thing to be noticed here is: it might be useful as well to have a way to run one command that would work through the entire queue, handing out jobs to their specific workers as needed.
Cons
lack of control over options, delays and etc
long running jobs might hang on the line, blocking small jobs
having multiple workers to tackle the above point might end up eating too much resources from the machine
Pros
Less stuff to configure on supervisor
Might be useful for smaller projects?
only one query to the database to get all jobs and distribute instead of one query per tube (things may get noisy if there's a lot of tubes to be worked)
This was already made in the main project, but I found no way to supply this feature in a good way from this queue package. Maybe we could add those classes and the developer simply extends/implements what's needed, since there's no way to reference a task that's outside of the main project files?
tasks/WorkTask.php
tasks/worker/Worker.php
tasks/traits/Options.php
The text was updated successfully, but these errors were encountered: