Jump to content
Mathroth

callback functions in "lazy cron" hook

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");
        }
    }

 

Share this post


Link to post
Share on other sites

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

  • Like 2

Share this post


Link to post
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');
  }

 

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By snobjorn
      I'd like to set up a LazyCron function that fires every hour on each page that has a template named "post". So far I have gotten the function running. But when it has fired once on "Page with Title A", it takes and hour before it is fired again on any other pages. It makes sense, hooking the function with wire()->addHook().
      What I want to do, is to get the function to be fired with LazyCron individually for each page. So that "Page with Title A" fires every hour (if it has pageviews), and "Page with Title B" is fired individually and possibly during the same timeline, if it has pageviews.
      Is this possible? Or might there be another way to utilize a sort of LazyCron on individual pages?
    • By MarkE
      LazyCron operates on an elapsed time interval, but you may want it to operate at specified times.
      Assuming your website is going to be visited sufficiently frequently (either by real users or by a Cron job), you can do this by editing the file /assets/cache/LazyCron.cache. This file contains 21 timestamps – one for each of the LazyCron specified intervals (e.g. “everyMinute”). The timestamp denotes when that interval was last triggered. To make the trigger happen at the required time, change the timestamp in the matching row to be when the previous trigger should have occurred.
      To make this easier, I have done an Excel spreadsheet (“Lazycron_fill.xlsx”) to simplify the process – just enter the required benchmark timings and copy the result into the LazyCron.cache file.
      Lazycron_fill.xlsx
    • By louisstephens
      I was really unsure of how to actually title this post, so I do apologize (if someone has a better idea, I will gladly edit it). I am using the profields: pagetable field to allow people to create their own "content" (copy, image, button, etc etc) and rearrange it. I also included a field called "column_size" using the RangeSlider set to (1-12).
      I guess I'll clarify a bit more on this. I am using flexbox where the "row" is <section></section> and the columns are <div class="column"></div> have given the "columns"  flex: 1 1 0; so no matter how many columns you have, the columns will automatically adjust for new content. Where my confusion is coming in: If a user has set up 3 copy items (with 12, 5, 7 respectfully for the column_size), how do I actually output this in my template? I was going to use a switch statement to handle the various items which I thought made it quite easy, but with closing sections and columns I have confused myself as I assume I need an if statement to check if the column size is > 12, or = 12 to determine the actual closing/opening of sections. I apologize if I have not made this very clear. I am a bit unsure how to word this let alone to go about this. 
      Im very appreciative of for any insight into this.
       
       
    • By VeiJari
      Hello forum! I'm trying to learn how to time up my functions by using lazycron but I can't get it fired up. 
      Here's my code in site/init.php:
      function setEventToRepeat(HookEvent $e) { $wire->log->message("kutsutaan cron"); $events = $wire->pages->find('template=tapahtuma'); die(var_dump($events)); $wire->log->message('Kaikki tapahtumat haettu:' .$events); }   $wire->addHook('LazyCron::every30Seconds', null, 'setEventToRepeat'); I get nothing in the logs and can't echo or dump anything
      Thanks for the help!
×
×
  • Create New...