Last active
February 2, 2017 15:41
-
-
Save hmic/e34b5ffa750453a3c666f7af0845cab5 to your computer and use it in GitHub Desktop.
Queuewrapper Testapp
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 | |
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', | |
], | |
]); | |
} | |
} |
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 | |
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