Task executed 3 times

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
psy
Power Poster
Power Poster
Posts: 463
Joined: Sat Jan 22, 2005 11:19 am

Task executed 3 times

Post 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
psy
Power Poster
Power Poster
Posts: 463
Joined: Sat Jan 22, 2005 11:19 am

[workaround] Re: Task executed 3 times

Post 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.
psy
Power Poster
Power Poster
Posts: 463
Joined: Sat Jan 22, 2005 11:19 am

Re: Task executed 3 times

Post 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?
ivanshum
Forum Members
Forum Members
Posts: 16
Joined: Sun Jul 03, 2011 10:01 am
Location: Russia

Re: Task executed 3 times

Post by ivanshum »

1. What value return self::LASTEXECUTE_SITEPREF?
2. What code in other functions of task (on_success,on_failure)?
Post Reply

Return to “Developers Discussion”