zf2-cron icon indicating copy to clipboard operation
zf2-cron copied to clipboard

cron service

Open isisis opened this issue 10 years ago • 3 comments

Hey,

I think you're not doing the things the ZF2 way. I was surprised when I saw:

Cron::register( 'foo', '*/15 * * * *', 'Foo::runCron', array('bar', 'baz') );

Why don't you make use of the service manager?

Where in the zf2 application are you exactly using this static call to add cron tasks? Bootstrap method of modules?

I would suggest to use a service that gets the configuration injected. In any module.config.php one could add then cron configurations like:

heartsentwinedCron => array( 'alias'=>'foo', 'route'=>'routeInYourRouteConfig', 'interval'=>'*/15 * * * *', 'properties'=>array( 'something'=>'bar', 'somethingElse'=>'baz' ), )

Then one could define a route in routes config and implement a custom controller where the route points to.

Something like this would be the ZF2 best practice.

isisis avatar Feb 07 '15 01:02 isisis

+1

Perfect-Web avatar Sep 12 '15 10:09 Perfect-Web

+1

popovserhii avatar May 29 '18 12:05 popovserhii

I've implemented a module which allows declaring cron jobs in the config

popovserhii avatar Jul 26 '18 19:07 popovserhii