woocommerce_segment = $woocommerce_segment; $this->woocommerce_helper = $woocommerce_helper; parent::__construct($timer); } function checkProcessingRequirements() { return $this->woocommerce_helper->isWooCommerceActive(); } function processTaskStrategy(ScheduledTask $task) { $meta = $task->getMeta(); $current_time = Carbon::createFromTimestamp(WPFunctions::get()->currentTime('timestamp')); $updated_at = Carbon::createFromTimestamp(strtotime($task->updated_at)); // If the task is running for too long consider it stuck and reschedule if (!empty($task->updated_at) && $updated_at->diffInMinutes($current_time, false) > self::TASK_RUN_TIMEOUT) { $task->meta = null; $this->reschedule($task, self::TIMED_OUT_TASK_RESCHEDULE_TIMEOUT); return false; } elseif (!empty($meta['in_progress'])) { // Do not run multiple instances of the task return false; } $task->meta = ['in_progress' => true]; $task->save(); $this->woocommerce_segment->synchronizeCustomers(); return true; } function complete(ScheduledTask $task) { $task->meta = null; return parent::complete($task); } }