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

Long running closure blocks other tasks #260

Closed
esetnik opened this issue Oct 29, 2019 · 9 comments
Closed

Long running closure blocks other tasks #260

esetnik opened this issue Oct 29, 2019 · 9 comments
Labels
Milestone

Comments

@esetnik
Copy link

esetnik commented Oct 29, 2019

Crunz version: x.y.z
v2.0.2
PHP version: x.y.z
v7.3.11
Operating system type and version:
docker php:7.3-fpm
Description
Running a long running task in closure blocks other tasks from executing.

How to reproduce
LongRunningTasks.php

$event = $schedule->run(function () {
        while (true) {
            echo 'output';
        }

})
->description('long-running-task')
->preventOverlapping();
$event
    ->everyMinute();

$event2 = $schedule->run(function () {
            echo 'another task';
})
->description('long-running-task')
->preventOverlapping();

$event2
    ->everyMinute();

return $schedule;

Possible Solution
The lavary implementation looks similar to the symphony process implementation for running processes asynchronously so I'm not sure why it doesn't work.

https://symfony.com/doc/current/components/process.html

$process = new Process(['ls', '-lsa']);
$process->start();

while ($process->isRunning()) {
    // waiting for process to finish
}

echo $process->getOutput();

Additional context

@PabloKowalczyk
Copy link
Collaborator

Did you mean, run long running task in one terminal, then try to run Crunz again with another terminal and other tasks from long running file will not be run?

@esetnik
Copy link
Author

esetnik commented Oct 29, 2019

No I mean that there'd be a single cron running with multiple tasks, one of those tasks will run forever, e.g. example above with infinite loop. The use case is to have an AWS SQS receive message task looping and being spawned by a crunz scheduler. In the example above, if I keep the first task looping, the second task never executes.

@PabloKowalczyk
Copy link
Collaborator

Sorry, I mean "is it a correct way to reproduce the issue?", but looks like it is.

@PabloKowalczyk PabloKowalczyk added this to the v2.0 milestone Nov 1, 2019
@PabloKowalczyk
Copy link
Collaborator

Hey @esetnik, could you run Crunz with -vvv option?

@PabloKowalczyk
Copy link
Collaborator

PabloKowalczyk commented Nov 17, 2019

Interesting issue, seems that there were two errors (both fixed). First, as described in #264, version v2.x changes behavior of Closures' return value, so Closures from your example were failing and this leads to second bug, locks were not released on task's error (fixed in #261). Test it with v2.0.4 release.

Thanks @esetnik.

@esetnik
Copy link
Author

esetnik commented Nov 17, 2019

Thank you for taking the time to look into this issue for me. I will update you once I get a chance to test this out. The solution seems reasonable and explains the odd behavior I was seeing.

@PabloKowalczyk
Copy link
Collaborator

@esetnik what about this issue? Could it be closed?

@esetnik
Copy link
Author

esetnik commented Dec 9, 2019

@PabloKowalczyk I apologize for the delay in getting back to you. This issue appears to be fixed now. Although it should be noted that a long running task which outputs to the console will eventually run out of memory due to #152 as far as I know.

@PabloKowalczyk
Copy link
Collaborator

#152 is a different topic, as a quick fix you could suppress any output from your "long running task" - should help.

I'm closing this issue, thanks @esetnik.

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

2 participants