anorgan / QuTee

PHP Background Jobs (Tasks) Manager
GNU Lesser General Public License v2.1
72 stars 12 forks source link

Worker persistor poling #18

Open m-hume opened 7 years ago

m-hume commented 7 years ago

Hi In the examples worker threads are implemented with the following code

while (true) {
    try {
        if (null !== ($task = $worker->run())) {
            echo 'Ran task: '. $task->getName() . PHP_EOL;
        }
    } catch (Exception $e) {
        echo 'Error: '. $e->getMessage() . PHP_EOL;
    }
}

Surely this will poll the persistor for new tasks as fast as it can? Should there not be some sort of delay in the loop? Or should it be implemented differently from the examples? cheers

anorgan commented 7 years ago

Worker has interval which you can modify. By default, it polls every 5 seconds

anorgan commented 7 years ago

In the readme there is an example: $worker->setInterval(30) will sleep for 30 secs

m-hume commented 7 years ago

Just checked the code When theres no tasks in the que it returns immediately without $this->_sleep(); line 146 of Worker.php

m-hume commented 7 years ago

just submitted the pull https://github.com/anorgan/QuTee/pull/19 cheers

anorgan commented 7 years ago

Tnx! Just released it. Tests fail on old versions of PHP because dependancy issues and on PHP 7 because TypeError is not handled well. Everything else works

m-hume commented 7 years ago

Thanks for sharing it in the first place! Looking like its going to be very usable. mh