Page 1 of 1

Task executed 3 times

Posted: Fri Dec 14, 2012 1:56 am
by psy
I have created a Task in lib/tasks and functionally it seems to be working OK. The task sends out email reminders to FEU's whose expiry date is getting near.

First real test was today and while the emails were sent, the task executed itself 3 times within a matter of seconds, ie each recipient got 3 emails.

Any idea why this would be?

The test function is:

Code: Select all

  public function test($time = '')
  {
    // Only perform this task daily.
    if( !$time ) $time = time();
    $last_execute = get_site_preference(self::LASTEXECUTE_SITEPREF,0);
    if( ($time - 24*60*60) >= $last_execute ) {
      return TRUE;
    }
    return FALSE;
  }
which is similar to the one in PruneAdminlog, ie:

Code: Select all

  public function test($time = '') {
    $lifetime = (int) get_site_preference(self::LIFETIME_SITEPREF, (60 * 60 * 24 * 31));
    if ($lifetime == -1) return FALSE; //only manual pruning

    // do we need to do this task.
    // we only do it daily.
    if (!$time) $time = time();
    $last_execute = get_site_preference(self::LASTEXECUTE_SITEPREF, 0);
    if (($time - 24 * 60 * 60) >= $last_execute) {
      return TRUE;
    }
    return FALSE;
  }



Would it be better to change the comparison to strings showing only Y-m-d? and if the day is greater, then execute?

The only other tasks in the directory are those that come standard with CMSMS, ClearCache, GatherNotifications and PruneAdminlog.

Suggestions for a solution welcome.

Thx
psy

[workaround] Re: Task executed 3 times

Posted: Sun Dec 16, 2012 10:41 pm
by psy
I set the psudo-cron jobs to run only once every 24hrs. Not ideal in a scenario where other crons jobs may need to run more frequently but it solved my problem.

Re: Task executed 3 times

Posted: Sun Dec 30, 2012 4:12 pm
by psy
FAIL!

Task was set both in code (as per examples and tasks installed by default) and prefs to send once per day. One day task was supposed to send 100 emails. Instead it sent 1500 before host took site offline. Each recipient received 15 copies.

There is a serious logic problem!

Not sure whether to look for answers here or submit bug report.

Ideas for a fix?

Re: Task executed 3 times

Posted: Wed Jan 30, 2013 6:30 am
by ivanshum
1. What value return self::LASTEXECUTE_SITEPREF?
2. What code in other functions of task (on_success,on_failure)?