You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using your good cron php manager, connected to my database.
I want to log my cron executions to do a dashboard of all cronjobs and be able to manage the tasks in an dedicated interface with last execution result.
To store the result of a cron job I have to use your then() function but (perhaps as the issue 51) I've a problem with passing arguments to the then() function.
I've made some changes to your Job.php file to do that :
In Job.php
Juste after the line private $after; add :
/**
* Arguments to function executed after the job is executed.
*
* @var array
*/
private $afterArgs;
Add argument $args to then() declaration function to be : public function then(callable $fn, array $args, $runInBackground = false)
In then function, after $this->after = $fn; add :
$this->afterArgs = $args;
In finalize function change : call_user_func($this->after, $this->output, $this->returnCode);
by : call_user_func_array($this->after, array($this->afterArgs, $this->output, $this->returnCode));
It's done !
We can now call then function like then($afterExecutionFunction,array($arg1,$arg2));
And use this arguments from array in the function like :
$afterExecutionFunction=function($args, $output) {
print_r($args);
$arg1=$args[0];
$arg2=$args[1];
Do you think it's a good way to solve the problem ?
Thanks for this good php cron manager and hope this can interest somebody.
The text was updated successfully, but these errors were encountered:
@Adrienb91 it's a great suggestion, I am a bit worried about this being a breaking change. If you want to work on it and send me a PR I'll be more than happy to review it, if you do that just make sure not to introduce breaking changes
Hello,
I'm using your good cron php manager, connected to my database.
I want to log my cron executions to do a dashboard of all cronjobs and be able to manage the tasks in an dedicated interface with last execution result.
To store the result of a cron job I have to use your then() function but (perhaps as the issue 51) I've a problem with passing arguments to the then() function.
I've made some changes to your Job.php file to do that :
In Job.php
Juste after the line private $after; add :
/**
* Arguments to function executed after the job is executed.
*
* @var array
*/
private $afterArgs;
Add argument $args to then() declaration function to be : public function then(callable $fn, array $args, $runInBackground = false)
In then function, after $this->after = $fn; add :
$this->afterArgs = $args;
In finalize function change : call_user_func($this->after, $this->output, $this->returnCode);
by : call_user_func_array($this->after, array($this->afterArgs, $this->output, $this->returnCode));
It's done !
We can now call then function like then($afterExecutionFunction,array($arg1,$arg2));
And use this arguments from array in the function like :
$afterExecutionFunction=function($args, $output) {
print_r($args);
$arg1=$args[0];
$arg2=$args[1];
Do you think it's a good way to solve the problem ?
Thanks for this good php cron manager and hope this can interest somebody.
The text was updated successfully, but these errors were encountered: