Jump to content
VeiJari

Problem firing lazyCron

Recommended Posts

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!

Share this post


Link to post
Share on other sites

And for a site note I'm using schedulepages module, which uses lazyCron at it works perfectly.

Share this post


Link to post
Share on other sites

Have you debug mode on? I think $wire is not available in site/init.php.

Share this post


Link to post
Share on other sites
3 minutes ago, Soma said:

Have you debug mode on? I think $wire is not available in site/init.php.

Yes I've enabled debug mode and my other hooks are starting with $wire->addHookAfter...

Share this post


Link to post
Share on other sites

$wire is not available in site/init.php .... You need to use wire().

Share this post


Link to post
Share on other sites

Maybe your lazyCron is locked.

Look into your /site/assets/lazycron/ or in /site/assets/ folder. Don't know the exact path and name right now. 

There should be a lazycron file and maybe even a lazycron.locked file. The last one prevents LazyCron from working due to an error that occured before. 

  • Like 2

Share this post


Link to post
Share on other sites

Then if $wire works for the hook $wire inside the funtion doesn't work, need to use wire(). And yes the lock file is most likely the problem cause of using $wire inside your function.

  • Like 3

Share this post


Link to post
Share on other sites
1 hour ago, Soma said:

Then if $wire works for the hook $wire inside the funtion doesn't work, need to use wire(). And yes the lock file is most likely the problem cause of using $wire inside your function.

Ah, that explains it.

Thank you for clarifying it! Now it works 🙂

1 hour ago, wbmnfktr said:

Maybe your lazyCron is locked.

Look into your /site/assets/lazycron/ or in /site/assets/ folder. Don't know the exact path and name right now. 

There should be a lazycron file and maybe even a lazycron.locked file. The last one prevents LazyCron from working due to an error that occured before. 

This was also the problem, didn't know there was such a file! Thank you.

Share this post


Link to post
Share on other sites

Keep an eye on that file. It will save you lots of time knowing about it. Believe me. 😉 

  • Haha 1

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 Gadgetto
      Hi there,
      I'd like to prevent duplicate values in a specific page field (FieldtypeText) across all pages. The hook should also prevent saving of the page if a duplicate value is detected. Therefore I created two hook methods but I can't get it to work properly.
      Here are both hooks placed in init() method of an autoloader module:
      The first hook is to initially preset the field with the page id. The field value can be customized by the admin before saving.
      The second hook should check if the value is unique.
      If I create a new page and try to save, the WireException is already triggered in first step of page creation, where you enter the page title: SKU [] is already in use
      If I check the value of $sku (with Tracy) it's always empty!
      Any idea what could be wrong?
      EDIT: if I remove the second hook, the field value is correctly preset with the page id!
      $this->addHookAfter('Pages::added', $this, 'presetProductFields', ['priority' => 99]); $this->addHookAfter('Pages::saveReady', $this, 'checkSKUUnique', ['priority' => 101]); And this are the hook methods:
      public function presetProductFields(HookEvent $event) { $snipwire = $this->wire('snipwire'); if (!$snipwire) return; $page = $event->arguments(0); if ($snipwire->isProductTemplate($page->template)) { if ($page->hasfield('snipcart_item_id')) $page->setAndSave('snipcart_item_id', $page->id); } } /** * Check if the SKU value is unique across all product pages. * (Method triggered after Pages saveReady -> just before page is saved) * * @throws WireException * */ public function checkSKUUnique(HookEvent $event) { $snipwire = $this->wire('snipwire'); if (!$snipwire) return; $page = $event->arguments(0); if ($snipwire->isProductTemplate($page->template)) { $field = $page->getField('snipcart_item_id'); $sku = $page->snipcart_item_id; // SKU field value bd($sku); if ($page->isChanged('snipcart_item_id')) { $exists = $this->wire('pages')->get("snipcart_item_id=$sku"); if ($exists->id) { // value is not unique! $error = $this->_('SKU must be unique'); $exception = sprintf( $this->_('SKU [%s] is already in use'), $sku ); $inputfield = $page->getInputfield($field); $inputfield->error($error); throw new WireException($exception); // Prevent saving of non-unique value! } } } }  
    • By t0b1
      Hello there, and thanks for ProcessWire!
      I'm getting to know ProcessWire while doing my first project using it and I really like it so far.
      The challenge I'm facing right now is the following:
      I have a One-Pager using fullpage.js, realized as a single PW-Page containing a Repeater Field where each Repeater Item is one Section.
      Some Sections are supposed to have a little menu at the Top which references/links to different Sections of the Website, so I wanted to use a Checkbox Field "Top Menu" to decide if a Section gets a Menu and a Page Reference Field to choose the different Sections (Repeater Items) it should contain.
      I've already accomplished this by pasting the following code into /site/ready.php:
       
      $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) { if($event->object->hasField == 'top_menu_entries') { $page = $event->arguments('page'); if($page instanceof RepeaterPage) $page = $page->getForPage(); $event->return = $page->; } });  
      The only problem that still remains is that when I select the Entry of the Repeater Item itself it doesnt save the selection, meaning after I saved it's unselected again.
      On some Sections I do want a Menu-Entry for the Section itself though (which would be styled differently and not link anywhere) for Continuity-Reasons, any ideas on how to achieve that?
    • By Gadgetto
      Hi guys (didn't see any gals here),
      I have a module which has some custom helper classes. One of these classes has methods which are hookable. The class is derived from WireData. An additional complication is that this class has its own namespace. What would be the correct way to provide the hookable methods via API?
      Here is a very simplified code sample of the class:
      <?php namespace SnipWire\Services; use ProcessWire\WireData; use ProcessWire\WireException; class Webhooks extends WireData { ... public function ___handleOrderCompleted() { if ($this->debug) $this->wire('log')->save( self::snipWireWebhooksLogName, '[DEBUG] Webhooks request: handleOrderCompleted' ); $this->responseStatus = 202; // Accepted } public function ___handleOrderStatusChanged() { if ($this->debug) $this->wire('log')->save( self::snipWireWebhooksLogName, '[DEBUG] Webhooks request: handleOrderStatusChanged' ); $this->responseStatus = 202; // Accepted } ... } The class itself is invoked/used by a hook from within the main module:
      Depending of the event, one of the methods of the Webhooks class above is triggered. A developer should now be able to use one of the ___handle* methods to do further things.
      /** * Check for webohook request and process them. * (Method triggered before ProcessPageView::execute) * */ public function checkWebhookRequest(HookEvent $event) { if ($webhooksEndpoint = $this->get('webhooks_endpoint')) { if ($this->sanitizer->url($this->input->url) == $webhooksEndpoint) { /** @var Webhooks $webhooks Custom ProcessWire API variable */ $this->wire('webhooks', new Webhooks()); $this->wire('webhooks')->process(); $event->replace = true; // @note: Tracy Debug won't work from here on as normal page rendering is omitted! } } } Should I provide a custom API variable e.g. $webhooks? Or how is the best way to do this?
    • By Flashmaster82
      Hi, can you guys help a beginner with a problem..
      On my template (profile_page) i have a dropdown (page reference) where i can choose a sports team (team_page) that is related to that profile which is also its parent. Then on my Competition1 page (competition_page) I have page reference field (profiles) a dropdown that i want to display only profiles that has choose a specific sports team (template=team_page) the page parent to be specific.
      Structure/Template
      Sports_team1 (team_page)
           Profile1 (profile_page)
           Profile2 (profile_page)
           Profile3 (profile_page)
           Competition1 (competition_page)
       
      ready.php
      <?php $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) { if($event->object->hasField == 'profiles') { $relative = $page->parent->name; $event->return = $event->pages->find("template=profile_page, sports_team=$relative"); } }); ?> This returns with no results in the dropdown. If i remove sports_team=$relative then it displays all profiles that have profile_page as template, so it works almost. But i will have more sports teams so this is just an example. I only want to display the profiles that has choosen the parent team on there profile page in admin not front end.
      I hope i was able to explain it so you guys can understand a little bit. Need some help please! /Thanks
       
       
    • 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?
×
×
  • Create New...