wp = new WPFunctions(); $this->cron_helper = ContainerWrapper::getInstance()->get(CronHelper::class); $this->cron_worker_scheduler = ContainerWrapper::getInstance()->get(CronWorkerScheduler::class); } function getTaskType() { return static::TASK_TYPE; } function supportsMultipleInstances() { return static::SUPPORT_MULTIPLE_INSTANCES; } function schedule() { $this->cron_worker_scheduler->schedule(static::TASK_TYPE, $this->getNextRunDate()); } function checkProcessingRequirements() { return true; } function init() { } function prepareTaskStrategy(ScheduledTask $task, $timer) { return true; } function processTaskStrategy(ScheduledTask $task, $timer) { return true; } function getNextRunDate() { // random day of the next week $date = Carbon::createFromTimestamp($this->wp->currentTime('timestamp')); $date->setISODate((int)$date->format('o'), ((int)$date->format('W')) + 1, mt_rand(1, 7)); $date->startOfDay(); return $date; } function scheduleAutomatically() { return static::AUTOMATIC_SCHEDULING; } protected function getCompletedTasks() { return ScheduledTask::findCompletedByType(static::TASK_TYPE, CronWorkerRunner::TASK_BATCH_SIZE); } }