Schedules next launch or deletes queue item if it is not repeatable

@return bool Result of completing
@throws \Exception
766210
public function complete()
    {
        $this->last_run_date = date('Y-m-d H:i:s', time());
        if (0 != $this->next_task_id) {
            $this->status = DeferredQueue::STATUS_SUCCESS_AND_NEXT;
        } else {
            $this->status = DeferredQueue::STATUS_COMPLETE;
        }

        if ($this->planNextRun() === true) {
            return $this->save();
        } else {
            if ($this->delete_after_run) {
                return $this->delete() !== false;
            } else {
                return $this->save();
            }
        }
    }
944832
public function clear() {
		$this->request->allowMethod('post', 'delete');
		$ds = $this->QueueInfo->getDataSource();
		if ($ds->truncate($this->QueueInfo)) {
			$this->Flash->success(__d('cake_settings_app', 'The task queue has been cleared.'));
		} else {
			$this->Flash->error(__d('cake_settings_app', 'The task queue could not be cleared. Please, try again.'));
		}

		$urlRedirect = ['plugin' => 'cake_settings_app', 'controller' => 'queues', 'action' => 'index'];
		return $this->redirect($urlRedirect);
	}
1071607
public function process()
    {
        // Skip blank queues
        if (empty($this->batches)) {
            return true;
        }

        // Don't re-process completed queue
        if ($this->currentBatch >= count($this->batches)) {
            return true;
        }

        // Send current patch to indexes
        $this->prepareIndexes();

        // Advance to next batch if successful
        $this->setBatch($this->currentBatch + 1);
        return true;
    }
1013305
protected function performDeleteOnModel()
    {
        $results = $this->makeRequest($this->getEndpoint(), 'destroy', [
            $this->getKey()
        ]);

        // Creation failed
        if (!$results) {
            return false;
        }

        return true;
    }
589956
public function isDeliverable()
     {
         $deliverable = false;

         foreach ($this->getItems() as $item) {
             if ($item->Deliverable) {
                 $deliverable = true;
             }
         }

         return $deliverable;
     }
539483
protected function executeQueue()
    {
        foreach ($this->queueActions as $key => $action) {
            if (self::QUEUE_ACTION_PERSIST === $action) {
                $this->doPersist($this->queueManagerNames[$key], $this->queueModels[$key], $this->queueIds[$key]);
            } else {
                $this->manager->getPool()->getManager($this->queueManagerNames[$key])->remove($this->queueModels[$key]);
            }
        }

        $this->cleanQueue();
    }
850556
public function wait()
    {
        if ($this->process == null) {
            throw new \Exception('You must run `start` before running `wait`');
        }

        // blocks here until process completes
        $this->process->wait();

        if (!$this->process->isSuccessful()) {
            throw new \RuntimeException($this->process->getErrorOutput());
        }

        return $this->process->getOutput();
    }
313235
public function perform()
    {
        $instance = $this->getInstance();
        try {
            Event::trigger('beforePerform', $this);

            if(method_exists($instance, 'setUp')) {
                $instance->setUp();
            }

            $instance->perform();

            if(method_exists($instance, 'tearDown')) {
                $instance->tearDown();
            }

            Event::trigger('afterPerform', $this);
        }
        // beforePerform/setUp have said don't perform this job. Return.
        catch(DontPerform $e) {
            return false;
        }

        return true;
    }
471878
public function queue()
    {
        if (Event::fire(Event::JOB_QUEUE, $this) === false) {
            return false;
        }

        $this->redis->sadd(Queue::redisKey(), $this->queue);
        $status = $this->redis->rpush(Queue::redisKey($this->queue), $this->payload);

        if ($status < 1) {
            return false;
        }

        $this->setStatus(self::STATUS_WAITING);

        Stats::incr('queued', 1);
        Stats::incr('queued', 1, Queue::redisKey($this->queue, 'stats'));

        Event::fire(Event::JOB_QUEUED, $this);

        return true;
    }
166636
public function cancel() {
        switch ($this->state) {
            case self::STATE_SHEDULED:
                $this->state = self::STATE_NONE;
                $this->counter = 0;
                break;
        }
        return false;
    }
531839
public function execute() {
        global $DB;

        // Check if the category bin is disabled or there is no expiry time.
        $lifetime = get_config('tool_recyclebin', 'categorybinexpiry');
        if (!\tool_recyclebin\category_bin::is_enabled() || $lifetime <= 0) {
            return true;
        }

        // Get the items we can delete.
        $items = $DB->get_recordset_select('tool_recyclebin_category', 'timecreated <= :timecreated',
            array('timecreated' => time() - $lifetime));
        foreach ($items as $item) {
            mtrace("[tool_recyclebin] Deleting item '{$item->id}' from the category recycle bin ...");
            $bin = new \tool_recyclebin\category_bin($item->categoryid);
            $bin->delete_item($item);
        }
        $items->close();

        return true;
    }
455114
public function cancel()
    {
        if ($this->id === null) {
            return false;
        }

        $key = $this->queue->generateListKey();
        $id = "$key:" . $this->id;

        // Delete the job from the current and scheduled queue, then remove the job details from Redis
        $result = $this->queue->getClient()->getRedis()->multi()
            ->zrem($key)
            ->zrem($key . '-scheduled')
            ->del($id)
            ->hset(\date('Y-m-d') . '_cancel', (string)\time(), \json_encode([
                'class' => $this->getWorkerClass(),
                'args' => $this->getArgs(),
                'priority' => (float)$this->getPriority(),
                'id' => $this->getId()
            ]))
            ->exec();

        $this->workerClass = null;
        $this->args = [];
        $this->retry = null;
        $this->priority = null;

        return $result[0] === true || $result[1] === true;
    }
137512
public function poll()
    {
        $this->checkForNewSchedulers();

        foreach ($this->getMissedSchedules() as $scheduler) {
            $this->notifyIfChanges($scheduler);
            $this->setNextSchedule($scheduler);
        }

        foreach ($this->getOverdueNoExitSchedules() as $history) {
            $history->output = "No finish ping received by Eyewitness";
            $history->exitcode = 1;
            $history->save();

            if ($history->scheduler->alert_on_fail || ($history->scheduler->alert_run_time_greater_than > 0)) {
                $this->eye->notifier()->alert(new Overdue(['scheduler' => $history->scheduler]));
            }
        }

        foreach ($this->getConditionalSchedules() as $scheduler) {
            if ($this->hasNotRunInGivenTimeframe($scheduler)) {
                $this->notifyIfChanges($scheduler);
            }
        }
    }
982140
protected function initQueue()
	{
		if ($this->beingDestroyed) {
			throw new \RuntimeException(self::ERROR_BEING_DESTROY);
		}
		$this->idleQueue = new \SplQueue();
		$this->taskQueue = new \SplQueue();
		
		return $this;
	}
1318394
public function flush() {
    $count = count($this->queue);
    $success = true;

    while ($count > 0 && $success) {
      $batch = array_splice($this->queue, 0, min($this->batch_size, $count));
      $success = $this->flushBatch($batch);

      $count = count($this->queue);
    }

    return $success;
  }
1091254
public function delete()
    {
        if (!$this->queueName) {
            throw new \Exception('QueueName 队列名称不存在');
        }

        if (!$this->message) {
            throw new \Exception('Message 消息不存在');
        }

        $params = [
            'queueName'     => $this->queueName,
            'receiptHandle' => $this->message->get('receiptHandle'),
        ];

        $request = new DeleteMessageRequest($params);

        try {
            $this->client->send($request);
        } catch (RequestException $e) {
            throw $e;
        } catch (ResponseException $e) {
            $message = $e->getBody();

            if (!$message->has('code')) {
                throw $e;
            } else if (!in_array($message->get('code'), ['4430', '4440'])) {    // 4430：句柄无效，4440：队列不存在
                throw $e;
            }
        } catch (\Exception $e) {
            throw $e;
        }
    }
1299909
public function execute()
    {
        try {
            $this->scheduler->schedule();
            $this->messageManager->addSuccessMessage('Scheduled new TweakwiseExport');
        } catch (Exception $e) {
            $this->messageManager->addErrorMessage('Failed creating Tweakwise job');
        }

        return $this->createRefererRedirect();
    }