获取可用资源并传入回调
@param callable $task
@throws \RuntimeException
196196
protected function execute(callable $task)
	{
		if ($this->beingDestroyed) {
			throw new \RuntimeException(self::ERROR_BEING_DESTROY);
		}
		
		$this->taskQueue->enqueue($task);
		
		if ($this->idleQueue->isEmpty() && ($this->size + $this->beingCreatedSize) < $this->maxSize) {
			$this->newResource();
		}
		
		$this->taskDequeue();
	}
473297
public function add(AbstractTask $task)
    {
        $task->setRuntime($this->runtime);
        $this->registeredTasks[$task->getName()] = $task;
    }
898701
private function commit($task)
    {
        $lineConfig = false;
        $timetable = false;
        foreach ($task->getAmqpAcks() as $ack) {
            try {
                if ($ack->getPayload()->generated == true) {
                    $lineConfig = $this->getLineConfig($ack, $lineConfig);
                    $timetable = $this->getTimetable($ack, $lineConfig, $timetable);
                    $stopPoint = $this->getStopPoint($ack, $timetable);
                    if (empty($stopPoint)) {
                        $stopPoint = new StopPoint();
                        $stopPoint->setTimetable($timetable);
                        $stopPoint->setExternalId($ack->getPayload()->timetableParams->externalStopPointId);
                    }
                    $stopPoint->setPdfHash($ack->getPayload()->generationResult->pdfHash);
                    $pdfGenerationDate = new \DateTime();
                    $pdfGenerationDate->setTimestamp($ack->getPayload()->generationResult->created);
                    $stopPoint->setPdfGenerationDate($pdfGenerationDate);
                    $this->om->persist($stopPoint);
                    $this->mediaManager->saveStopPointTimetable(
                        $timetable,
                        $stopPoint->getExternalId(),
                        $ack->getPayload()->generationResult->filepath
                    );
                    $this->removeTmpMedia($timetable, $stopPoint->getExternalId());
                } elseif (isset($ack->getPayload()->error)) {
                    throw new \Exception('Ack error msg: ' . $ack->getPayload()->error);
                }
            } catch (\Exception $e) {
                $task->fail();
                echo "ERROR during task Completion, task n°" . $task->getId() . "\n";
                echo $e->getMessage() . "\n";
            }
        }
        $task->complete();
    }
1275107
public function setTask(Task $task = null)
    {
        $this->task = $task;
        if (null !== $task) {
            $task->addTransition($this);
        }

        return $this;
    }
40183
public static function addTask($task, $frequency = 60)
    {
        self::initEvn();

        $frequency < 1 || $frequency = 60;

        $task || self::message('task is empty');

        $status = self::getStatus();

        isset($status['task']) || $status['task'] = [];

        $key = md5($task);
        isset($status['task'][$key]) || $status['task'][$key] = [
            'last_runtime' => 0,//上一次运行时间
            'frequency' => $frequency,//执行的频率
            'task' => $task
        ];
        file_put_contents(self::$status, '<?php return ' . var_export($status, true) . ';', LOCK_EX);

        self::message('task nums (' . count($status['task']) . ') list  [' . json_encode($status['task'], JSON_UNESCAPED_UNICODE) . ']');
    }
1183198
public function updateTask($task): Google_Service_Tasks
    {
        if ($task instanceof Tasks) {
            $task = $task->googleTasks;
        }

        return $this->service->tasks->update($this->tasklist, $task->id, $task);
    }
1022794
protected function submitTask(Task $task)
    {
        switch ($task->type) {
        case Task::JOB_LOW:
            $type = 'submit_job_low';
            break;
        case Task::JOB_LOW_BACKGROUND:
            $type = 'submit_job_low_bg';
            break;
        case Task::JOB_HIGH_BACKGROUND:
            $type = 'submit_job_high_bg';
            break;
        case Task::JOB_BACKGROUND:
            $type = 'submit_job_bg';
            break;
            case Task::JOB_EPOCH:
            $type = 'submit_job_epoch';
            break;
        case Task::JOB_HIGH:
            $type = 'submit_job_high';
            break;
        default:
            $type = 'submit_job';
            break;
        }

        $arg = $task->arg;

        $params = array(
            'func' => $task->func,
            'uniq' => $task->uniq,
            'arg' => $arg,
        );

        if ($task->type == Task::JOB_EPOCH) {
            $params['epoch'] = $task->epoch;
        }

        $s = $this->getConnection();
        Connection::send($s, $type, $params);

        if (!is_array(Connection::$waiting[(int) $s])) {
            Connection::$waiting[(int) $s] = array();
        }

        array_push(Connection::$waiting[(int) $s], $task);
    }
582781
public function run($workload, TaskWrapper $task)
    {
        $result = false;
        $this->id = $task->getId();
        $this->name = $task->getName();

        try {
            if (false !== $this->beforeRun($workload, $task)) {
                $result = $this->doRun($workload, $task);

                $this->afterRun($result);
            }
        } catch (\Exception $e) {
            $this->onException($e);
        }

        return $result;
    }
722253
public function setTask($task)
    {
        $taskCode = filter_var($task, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
        if (strpos($taskCode, '-') !== false) {
            $taskCode = str_replace('-', '', $taskCode);
        }
        $taskCode = $this->project . $taskCode;
        $this->task = $taskCode;
    }
530869
public function addTask(Task $task)
    {
        if (!isset($this->tasks[$task->uniq])) {
            $this->tasks[$task->uniq] = $task;
            ++$this->tasksCount;
        }
    }
151429
protected function handleError($response) {
    $errorMsg = $response->getValue('errorMsg');
    self::$logger->error("Error in remote call to ".$this->serverUrl.": ".$errorMsg."\n".$response->toString(), __FILE__);
    throw new \RuntimeException("Error in remote call to ".$this->serverUrl.": ".$errorMsg);
  }
1233904
public function removeStartTask(\Stackable $task) {
        if ($this->workerStartTasks->contains($task)) {
            $this->workerStartTasks->detach($task);
        }
    }
262608
public function addObject( $object )
	{
		if( !is_object( $object ) )
			throw new InvalidArgumentException( 'Not an object given' );
		$reflection	= new ReflectionObject( $object );
		$methods	= $reflection->getMethods();
		foreach( $methods as $method )
		{
			if( in_array( $method->name, $this->delegableMethods ) )
				throw new RuntimeException( 'Method "'.$method->name.'" is already set' );
			$this->delegableMethods[]	= $method->name;
		}
		$this->delegableObjects[]	= $object;
	}
445653
public function startTask($task, array $options = [])
    {
        ob_start() && $this->taskStack[] = $task;

        $this->taskOptions[$task] = $this->mergeDefaultOptions($options);
    }
968316
public function setMethod($method = self::GET)
	{
		if (in_array($method, $this->allowedMethods)) {
			$this->method = $method;
		} else {
			throw new RuntimeException('Invalid method setted.');
		}
		
		return $this;
	}
408908
public function task($task, Closure $callback = null)
    {
        foreach ($this->connections as $connection) {
            $connection->task($task, $callback);
        }
    }
147727
public function update(Task $task): Task
    {
        $id = $task->getId();

        $task->setId(null);

        $response = $this->client->put($this->prepareUrlForKey('update-task', ['id' => $id]), [], $task->jsonSerialize());
        $responseData = $response->getDecodedBody();

        return new Task($responseData);
    }