/** * Adds the task to a queue. * * @param string $queue The name of the queue to add to. Defaults to * 'default'. * * @return string The name of the task. * * @throws TaskAlreadyExistsException if a task of the same name already * exists in the queue. * @throws TaskQueueException if there was a problem using the service. */ public function add($queue_name = 'default') { $queue = new PushQueue($queue_name); return $queue->addTasks([$this])[0]; }
/** * @param FriendResponse[] $friends */ protected function _queueFriends(array $friends) { $chunks = array_chunk($friends, 5); foreach ($chunks as $friends) { $tasks = []; foreach ($friends as $friend) { $tasks[] = new PushTask('/cron/update-user', ['user' => $friend->steamId], ['name' => 'a' . $friend->steamId]); } try { $queue = new PushQueue('update-user'); $queue->addTasks($tasks); } catch (TaskAlreadyExistsException $e) { } } }
public function testPushQueueTooManyTasksError() { $req = self::buildBulkAddRequestWithTwoTasks(); $resp = new TaskQueueBulkAddResponse(); $task_result = $resp->addTaskResult(); $task_result->setResult(ErrorCode::OK); $task_result->setChosenTaskName('fred'); $task_result = $resp->addTaskResult(); $task_result->setResult(ErrorCode::TOO_MANY_TASKS); $task_result->setChosenTaskName('bob'); $this->setExpectedException('\\google\\appengine\\api\\taskqueue\\TaskQueueException', 'Too many tasks in request.'); $this->apiProxyMock->expectCall('taskqueue', 'BulkAdd', $req, $resp); $task1 = new PushTask('/someUrl'); $task2 = new PushTask('/someOtherUrl'); $queue = new PushQueue(); $queue->addTasks([$task1, $task2]); $this->apiProxyMock->verify(); }