Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can circular tasks be asynchronous? #58

Open
siyecoo opened this issue Mar 29, 2020 · 7 comments
Open

Can circular tasks be asynchronous? #58

siyecoo opened this issue Mar 29, 2020 · 7 comments
Labels

Comments

@siyecoo
Copy link

siyecoo commented Mar 29, 2020

$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
}

@kstkn kstkn added the question label Mar 29, 2020
@kstkn
Copy link
Collaborator

kstkn commented Mar 29, 2020

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

@siyecoo
Copy link
Author

siyecoo commented Mar 29, 2020

@kstkn
$schedule->command('order1')->cron('* * * * ');
// method order1 needs sleep 3s synchronization block In addition, order2,command execution will block
$schedule->command('order2')->cron('
* * * *');

Repository owner deleted a comment from siyecoo Mar 29, 2020
@kstkn
Copy link
Collaborator

kstkn commented Mar 29, 2020

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

@siyecoo
Copy link
Author

siyecoo commented Mar 29, 2020

@kstkn Thank you very much for your guidance.

@kstkn
Copy link
Collaborator

kstkn commented Mar 29, 2020

no problems, @siyecaoya. Does this answer your question?

@siyecoo
Copy link
Author

siyecoo commented Mar 29, 2020

@kstkn Should not. The business scenario is limited. I need to verify it

@JimChenWYU
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants