Skip to content

Instantly share code, notes, and snippets.

@hmic
Last active February 2, 2017 15:41
Show Gist options
  • Save hmic/e34b5ffa750453a3c666f7af0845cab5 to your computer and use it in GitHub Desktop.
Save hmic/e34b5ffa750453a3c666f7af0845cab5 to your computer and use it in GitHub Desktop.
Queuewrapper Testapp
<?php
namespace App\Shell;
use Cake\Console\Shell;
use Josegonzalez\CakeQueuesadilla\Queue\Queue;
/**
* Queue shell command.
*/
class QueueShell extends Shell
{
function some_job() {
var_dump(func_get_args());
}
public function main()
{
Queue::push('App\Lib\QueueWrapper::extract', [
'callable' => ['\App\Shell\QueueShell', 'some_job'],
'args' => [
'id' => 7,
'message' => 'hi',
],
]);
Queue::push('App\Lib\QueueWrapper::extract', [
'callable' => ['\App\Lib\QueueWrapper', 'some_job'],
'args' => [
'id' => 8,
'message' => 'ho',
],
]);
Queue::push('App\Lib\QueueWrapper::extract', [
'callable' => [__CLASS__, 'some_job'],
'args' => [
'id' => 9,
'message' => 'now',
],
]);
}
}
<?php
namespace App\Lib;
class QueueWrapper {
static function extract($job) {
$callable = $job->data('callable');
if(is_array($callable) && count($callable) == 2) {
$instance = new $callable[0];
return call_user_func_array([$instance, $callable[1]], $job->data('args'));
}
return call_user_func_array($callable, $job->data('args'));
}
public function some_job() {
var_dump(func_get_args());
}
}
// call with: Queue::push(['App\Lib\QueueWrapper::extract'], ['callable '=> [__CLASS__, 'some_job'], 'args' => [1, 'me']]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment