Dadog Posted September 17, 2014 Share Posted September 17, 2014 Is it possible to call LazyCron in a Process (Admin) module? I've built an XML importscript to import pages via het API. Everything is working fine. I wanted to automate this module and run it at a particular time e.g. once a day. I've implemented LazyCron in my module like so: class dataImport extends Process implements Module { public function init() { parent::init(); $this->addHook('LazyCron::everyMinute', $this, 'myFunc'); } public function myFunc() { Do some stuff ... } } To my understanding the Process module is only activated in the backend and not the frontend? So when LazyCron kicks in on the front-end, Process modules addHook are not included in the execution? This the behaviour that we see now ... the hooks are executed when someone is working in the module, but not on the frontend ... How do I fix this and is this even possible? Link to comment Share on other sites More sharing options...
LostKobrakai Posted September 17, 2014 Share Posted September 17, 2014 I think the easiest would be to separate the admin page (process module) from the data importer, this way the importer would be independent from admin page views. Link to comment Share on other sites More sharing options...
sforsman Posted September 17, 2014 Share Posted September 17, 2014 Like LostKobrakai said, you want to create a separate module that does the hooking. The key is to make it autoloadable (it usually makes sense to make it singular too). This way the hook will always be active, regardless of where you are. Here's a simple example class MyHookingModule extends WireData implements Module { public static function getModuleInfo() { return Array( 'title' => 'MyHookingModule', 'summary' => 'Just a demo module', 'version' => 1, 'autoload' => true, 'singular' => true, ); } public function init() { $m = $this->modules->get("dataImport"); $this->addHook('LazyCron::everyMinute', $m, 'myFunc'); } } However I would definitely suggest doing it like LostKobrakai suggested. Separate the Process-module from the importing module and with the Process-module, provide only PW admin-related aspects. Link to comment Share on other sites More sharing options...
Dadog Posted September 17, 2014 Author Share Posted September 17, 2014 Thx, guys! Really nice feedback, I will go with the separate route! Link to comment Share on other sites More sharing options...
RyanJ Posted October 9, 2014 Share Posted October 9, 2014 I would be interested in seeing your solution Dadog if you would not mind sharing. I am trying to use LazyCron with the Clean Empty Page Files Dir. I am wanting to run the clean directory module with the Every30Minutes hook offered by LazyCron on front-end page views, but kinda confused on how I should approach it. Thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now