You are here

public function Cron::addTask in Anti Spam by CleanTalk 9.1.x

Same name and namespace in other branches
  1. 8.4 src/lib/Cleantalk/Common/Cron.php \Cleantalk\Common\Cron::addTask()

Adding new cron task.

Parameters

string $task:

string $handler:

int $period:

null|int $first_call:

array $params:

Return value

bool

1 call to Cron::addTask()
Cron::updateTask in src/lib/Cleantalk/Common/Cron.php
Updates cron task, create task if not exists.

File

src/lib/Cleantalk/Common/Cron.php, line 96

Class

Cron
CleanTalk Cron class

Namespace

Cleantalk\Common

Code

public function addTask($task, $handler, $period, $first_call = null, $params = array()) {

  // First call time() + period
  $first_call = !$first_call ? time() + $period : $first_call;
  if (isset($this->tasks[$task])) {
    return false;
  }

  // Task entry
  $this->tasks[$task] = array(
    'handler' => $handler,
    'next_call' => $first_call,
    'period' => $period,
    'params' => $params,
  );
  return $this
    ->saveTasks($this->tasks);
}