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

Allowing arguments for then() function #85

Open
Adrienb91 opened this issue Sep 22, 2019 · 1 comment
Open

Allowing arguments for then() function #85

Adrienb91 opened this issue Sep 22, 2019 · 1 comment

Comments

@Adrienb91
Copy link

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.

@peppeocchi
Copy link
Owner

@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

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

No branches or pull requests

2 participants