-
Notifications
You must be signed in to change notification settings - Fork 64
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
Jobs execute just once. #49
Comments
Hello mockingbirdnj83, Thanks for using Cron. Please follow the README. Since version 1 of Cron you can use a build in route and don't have to create a own route. For this you can define your jobs in the Event::listen('cron.collectJobs', function() {
Cron::add('example1', '* * * * *', function() {
// Do some crazy things unsuccessfully every minute
return 'No';
});
Cron::add('example2', '*/2 * * * *', function() {
// Do some crazy things successfully every two minute
return null;
});
Cron::add('disabled job', '0 * * * *', function() {
// Do some crazy things successfully every hour
}, false);
}); Now please generate a route security key via After this is done you should have a new line in the cron_manager table every minute. Best Regards, |
Thanks to answer me so quickly. Let me explain : I have a form with fields corresponding to the parameters of my script. When I get these datas from the form, I would like to open a Cron that create a command line with them, and use shell_exec() to call my script with this command line. (I have shell access). Something like this : Cron::add('alert8', $pattern, function($parameter) {
$cmd = './script/main.php';
if ($parameter->foo == 1) {
$cmd += ' -foo';
} else if ($parameter->bar) {
$cmd += " -bar $parameter->bar";
}
exec($cmd);
return null;
}, true); If I must use Cron:add in global.php I can't automate the Cron creation (without opening and writing in the file with php. And I would like to avoid this). It's why I'm wondering if there is a way to call Cron:add elsewhere than global.php ? |
Okay I understand that you want to add Cron jobs dynamically. But I don't understand the way you do this. If you send the form, you will add a Cron job and you will start Cron. After this is done and the request is handled, PHP will shut down and delete all the memory. So your added Cron job is gone because it is only added to the memory at runtime. For that reason you have to save the dynamic Cron job information somewhere else. I would recommend a database for this. For dynamic Cron jobs your database table Event::listen('cron.collectJobs', function() {
// TODO Run through cron_definitions via foreach and execute
Cron:add($name, $expression, function() use ($function) {
$return = eval($function);
if ($return === FALSE) {
return 'Parse Error of function ' . $function;
} else {
return $return;
}
});
}); Now you can use Crons build in route or the artisan command Please note that the eval function could be a security risk. I hope this helps. Best Regards, |
Hello Liebig. Thanks a lot for your answers. I understand what you said about the memory. And your idea is very relevant. It's definitely what I need. function() use ($function) I never seen this before. One more time, thanks. |
Hi mockingbirdnj83, |
Hello Liebig, Thanks again for it and for all your efforts. Thomas. |
Hi Thomas, Best Regards |
Hello,
I have a script checking errors on webpages. I'm trying to develop a tool with Laravel to manage 'alerts' (automated calls to this script to maintain a surveillance).
But I'm a bit confused about how to using your lib.
When I add a cron like this :
I get a new line in cron_manager like this :
| 719 | 2014-12-04 14:29:02 | 0.00 |
And a new line in cron_jobs like this :
| 11 | example1 | Example 1 ran | 0.00 | 719 |
But nothing else. As far as I understand, I should have a new line in cron_manager every minutes. But I don't.
Must I use Event::listen('cron.collectJobs') to add crons ? What does it concretely do ?
Can I call Cron::add everywhere in the app ?
Sorry for my mistakes, English isn't my native language.
Thank you in advance.
The text was updated successfully, but these errors were encountered: