Jump to content

Recommended Posts

Posted

I am facing a strange issue with lazycron,

maybe I don't use it properly.

It is called within the main template, and it is set to trigger every 30 minutes :

wire()->addHook('LazyCron::every30Minutes', null, 'publish_new_stuff');

For debugging purposes, the triggered function starts with logging inside a text file :

function publish_new_stuff(HookEvent $e)
{
$log = new FileLog(wire('config')->paths->logs . 'my-log2.txt');
$log->save('coucou inside lazycron');
...

What I observe is :

- it used to work

- then since a few days it is not triggered anymore (the log file is not updated)

- as soon as I change the time interval to everyMinute, every2Minutes, or every5Minutes, then it is working again

- as soon as I change the time interval to every10Minutes, every30Minutes, every45Minutes, or everyHour, then it STOPS working

- I have uninstalled/reinstalled the LazyCron module from the backend, no change

any idea ?

what can I do to further troubleshoot or fix ?

thanks

Posted

thanks, I should have mentioned, yes I know it's lazy, 

and yet it does not trigger, even tough I make sure that I force the needed page refreshes.

Posted

Thanks er314, I'll do some testing here and see if I can duplicate it (and fix it if so). If not, I might need to get more details on how to reproduce, but I think I've got enough to go on for now. 

  • 1 year later...
Posted

Hi Ryan,

I know it's has been a while but is there any potential cause for this issue? I am having the same issue with 2.5.7, I setup a module with lazycron hook couple days ago and it works perfectly but after several days it stops working and I just couldn't identify why. No errors being logged which tells me lazycron is not being triggered at all.

Here's my module if that helps:

<?php

  /**
   * ProcessWire 'Hello world' demonstration module
   *
   * Demonstrates the Module interface and how to add hooks.
   *
   * See README file for further links regarding module development.
   *
   * ProcessWire 2.x
   * Copyright (C) 2014 by Ryan Cramer
   * Licensed under GNU/GPL v2, see LICENSE.TXT
   *
   * http://processwire.com
   *
   */

  class Helloworld extends WireData implements Module {

    /**
     * getModuleInfo is a module required by all modules to tell ProcessWire about them
     *
     * @return array
     *
     */
    public static function getModuleInfo() {

      return array(

        // The module'ss title, typically a little more descriptive than the class name
          'title' => 'Hello World',

        // version number
          'version' => 2,

        // summary is brief description of what this module is
          'summary' => 'An example module used for demonstration purposes. See the /site/modules/Helloworld.module file for details.',

        // Optional URL to more information about the module
          'href' => 'http://processwire.com',

        // singular=true: indicates that only one instance of the module is allowed.
        // This is usually what you want for modules that attach hooks.
          'singular' => true,

        // autoload=true: indicates the module should be started with ProcessWire.
        // This is necessary for any modules that attach runtime hooks, otherwise those
        // hooks won't get attached unless some other code calls the module on it's own.
        // Note that autoload modules are almost always also 'singular' (seen above).
          'autoload' => true,

        // Optional font-awesome icon name, minus the 'fa-' part
          'icon' => 'smile-o',
      );
    }

    /**
     * Initialize the module
     *
     * ProcessWire calls this when the module is loaded. For 'autoload' modules, this will be called
     * when ProcessWire's API is ready. As a result, this is a good place to attach hooks.
     *
     */
    public function init() {
      $this->addHook('LazyCron::every30seconds', $this, 'fetch');
    }

    /**
     * Example1 hooks into the pages->save method and displays a notice every time a page is saved
     *
     */
    public function fetch($interval = null) {
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, 'https://api.instagram.com/v1/users/1334465068/media/recent/?client_id=xxx');
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_TIMEOUT, 20);
      $result = curl_exec($ch);
      curl_close($ch);

      $result = json_decode($result);
      $urls = "";

      foreach ($result->data as $post) {
        $urls .= $post->images->standard_resolution->url . ",";
      }

      if (strlen($urls) > 0) {
        $p = wire('pages')->get(1018);
        $p->setOutputFormatting(false);
        $p->instagram_urls = trim($urls, ",");
        $p->save('instagram_urls');
        $p->setOutputFormatting(true);
      }
    }
  }

Any help to know what's the issue was, is much appreciated! :)

Thanks

  • 5 months later...
Posted

I am not sure, but it seems like I am having a similar problem. I think I did get a autoload module to hook Lazy Cron, but then it stopped working. I did mess around the system time a bit while testing - changed dates. Maybe this caused it to stop functioning?

Could you please suggest how I can properly test it out? I am still not quite sure if Lazy Cron is not working or I screwed up my module.

  • Like 1
Posted

Ivan, you should have a look into the sites/assets/cache folder. If you can find a file there called LazyCronLock.cache, it is a sign that LazyCron once has started, but get not finished.

To see when it has started, you may have a look to file date lastmodified, or look into it, it only contains a unixtimestamp.

The reason(s) why it doesn't get finished could be that a script gots crashed / interrupted badly, - that a script is running in an endless loop, - or something that like.

  • Like 2
Posted

I have got only LazyCron.cache but not LazyCronLock.cache. In there I see some timesatmps, latest of which is of yesterday, though I certainly tried to make it work today. Is there a way to restart that lazy cron job? Should I just delete that LazyCron.cache file? Could it be that this module can only properly function on a live server but not on localhost?

Posted

It should work on localhost too, but it needs pageViews to get triggered, (but you know that). No, I think deleting the LazyCron.cache file doesn't matter. Only that with the Lock file I have had, and there it has helped to reanimate it. :mellow:

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.
×
×
  • Create New...