Open siyecoo opened 4 years ago
Not sure I fully understand the question.
The statement $schedule->command($command)->cron('...')
itself is asynchronous
Each event though will block execution if it doesn't have callbacks. See \omnilight\scheduling\Event::run
@kstkn $schedule->command('order1')->cron(' '); // method order1 needs sleep 3s synchronization block In addition, order2,command execution will block $schedule->command('order2')->cron(' ');
Sorry, @siyecaoya, I still don't get it. I'll try to make an assumption that what your issue is that you want two commands (events) to be executed asynchronously. In current implementation that is only possible to achieve using callbacks, see example:
$schedule->command('first')->cron('* * * * *')->then(function() {});
$schedule->command('second')->cron('* * * * *')->then(function() {});
With callbacks (then
) method runCommandInBackground
will be used, hence command execution will not be blocking.
I hope that helps :)
If not, pls, explain what are you trying to do or wait until other people comment
@kstkn Thank you very much for your guidance.
no problems, @siyecaoya. Does this answer your question?
@kstkn Should not. The business scenario is limited. I need to verify it
it use exec
to run command, so just let it run in background, it will be asynchronous.
https://www.php.net/manual/en/function.exec.php#86329
$scheduleList = Schedule::find()->where(['is_enabled' => 1, 'task_type' => 1])->asArray()->all();
if (empty($scheduleList)) exit('无效用户队列!!');
foreach ($scheduleList as $key => $item) { $schedule->command($command)->cron($item['execute']);//Synchronous block }