zf2-cron
zf2-cron copied to clipboard
cron service
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.
+1
+1
I've implemented a module which allows declaring cron jobs in the config