Jump to content

callback functions in "lazy cron" hook


Mathroth
 Share

Recommended Posts

hello to all processwire dudes... I need your help again :lol: As you can see in my code i want to call a simple function i the processwire lazy cron hook. Lazy cron works and execute the "echo 30 seconds have passed!" But the function syncMobileDE();  does not return any results. Thanks for your advises! 

public function init() {
        $this->addHook('LazyCron::every30Seconds', $this, 'myHook');
    }

public function myHook(HookEvent $e) {  
         $seconds = $e->arguments[0];
         echo "30 seconds have passed!";
          $this->syncMobileDE();
    }

 public function syncMobileDE($event) {
        /** @var Page $page */
        $page = $event->arguments(0);
        if($page->template->name == 'fahrzeugangebot') {
           $this->listCars();
           $this->initDetail();
           $this->message("Mobile.de synchronisiert");
        }
    }

 

Link to comment
Share on other sites

On 10.4.2017 at 3:30 PM, rick said:

Your function takes an argument but your hook is not passing one?

    public function myHook(HookEvent $e) {  
         $seconds = $e->arguments[0];
         $this->syncMobileDE($e);
         echo "30 seconds have passed!";
         
    }

Changed it with the argument. Unfortunately the function doesn't execute. The "echo" is displayed on every page. So the error might be in the syncMobileDE() Function. I also use the function with a hook on "Pages::save" and there it works. :-X

  public function init() {
		...
        $this->pages->addHookAfter('Pages::save', $this, 'syncMobileDE');
  }

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...