本文整理匯總了Python中google.appengine.api.taskqueue.Task方法的典型用法代碼示例。如果您正苦於以下問題:Python taskqueue.Task方法的具體用法?Python taskqueue.Task怎麽用?Python taskqueue.Task使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類google.appengine.api.taskqueue
的用法示例。
在下文中一共展示了taskqueue.Task方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _run_task_hook
# 需要導入模塊: from google.appengine.api import taskqueue [as 別名]
# 或者: from google.appengine.api.taskqueue import Task [as 別名]
def _run_task_hook(hooks, method, task, queue_name):
"""Invokes hooks.method(task, queue_name).
Args:
hooks: A hooks.Hooks instance or None.
method: The name of the method to invoke on the hooks class e.g.
"enqueue_kickoff_task".
task: The taskqueue.Task to pass to the hook method.
queue_name: The name of the queue to pass to the hook method.
Returns:
True if the hooks.Hooks instance handled the method, False otherwise.
"""
if hooks is not None:
try:
getattr(hooks, method)(task, queue_name)
except NotImplementedError:
# Use the default task addition implementation.
return False
return True
return False
示例2: schedule
# 需要導入模塊: from google.appengine.api import taskqueue [as 別名]
# 或者: from google.appengine.api.taskqueue import Task [as 別名]
def schedule(cls, base_path, mapreduce_spec):
"""Schedule finalize task.
Args:
mapreduce_spec: mapreduce specification as MapreduceSpec.
"""
task_name = mapreduce_spec.mapreduce_id + "-finalize"
finalize_task = taskqueue.Task(
name=task_name,
url=base_path + "/finalizejob_callback",
params={"mapreduce_id": mapreduce_spec.mapreduce_id})
queue_name = os.environ.get("HTTP_X_APPENGINE_QUEUENAME", "default")
if not _run_task_hook(mapreduce_spec.get_hooks(),
"enqueue_controller_task",
finalize_task,
queue_name):
try:
finalize_task.add(queue_name)
except (taskqueue.TombstonedTaskError,
taskqueue.TaskAlreadyExistsError), e:
logging.warning("Task %r already exists. %s: %s",
task_name, e.__class__, e)
示例3: get_callback_task
# 需要導入模塊: from google.appengine.api import taskqueue [as 別名]
# 或者: from google.appengine.api.taskqueue import Task [as 別名]
def get_callback_task(self, *args, **kwargs):
"""Returns a task for calling back this Pipeline.
Args:
params: Keyword argument containing a dictionary of key/value pairs
that will be passed to the callback when it is executed.
args, kwargs: Passed to the taskqueue.Task constructor. Use these
arguments to set the task name (for idempotence), etc.
Returns:
A taskqueue.Task instance that must be enqueued by the caller.
"""
if not self.async:
raise UnexpectedPipelineError(
'May only call get_callback_task() method for asynchronous pipelines.')
params = kwargs.get('params', {})
kwargs['params'] = params
params['pipeline_id'] = self._pipeline_key.name()
kwargs['url'] = self.base_path + '/callback'
kwargs['method'] = 'POST'
return taskqueue.Task(*args, **kwargs)
示例4: cleanup
# 需要導入模塊: from google.appengine.api import taskqueue [as 別名]
# 或者: from google.appengine.api.taskqueue import Task [as 別名]
def cleanup(self):
"""Clean up this Pipeline and all Datastore records used for coordination.
Only works when called on a root pipeline. Child pipelines will ignore
calls to this method.
After this method is called, Pipeline.from_id() and related status
methods will return inconsistent or missing results. This method is
fire-and-forget and asynchronous.
"""
if self._root_pipeline_key is None:
raise UnexpectedPipelineError(
'Could not cleanup Pipeline with unknown root pipeline ID.')
if not self.is_root:
return
task = taskqueue.Task(
params=dict(root_pipeline_key=self._root_pipeline_key),
url=self.base_path + '/cleanup',
headers={'X-Ae-Pipeline-Key': self._root_pipeline_key})
taskqueue.Queue(self.queue_name).add(task)
示例5: __add_kickoff_task
# 需要導入模塊: from google.appengine.api import taskqueue [as 別名]
# 或者: from google.appengine.api.taskqueue import Task [as 別名]
def __add_kickoff_task(cls, job_config, mapreduce_spec):
"""Add kickoff task to taskqueue.
Args:
job_config: map_job.JobConfig.
mapreduce_spec: model.MapreduceSpec,
"""
params = {"mapreduce_id": job_config.job_id}
# Task is not named so that it can be added within a transaction.
kickoff_task = taskqueue.Task(
# TODO(user): Perhaps make this url a computed field of job_config.
url=job_config._base_path + "/kickoffjob_callback/" + job_config.job_id,
headers=util._get_task_headers(job_config.job_id),
params=params)
if job_config._hooks_cls:
hooks = job_config._hooks_cls(mapreduce_spec)
try:
hooks.enqueue_kickoff_task(kickoff_task, job_config.queue_name)
return
except NotImplementedError:
pass
kickoff_task.add(job_config.queue_name, transactional=True)
示例6: decode_payload
# 需要導入模塊: from google.appengine.api import taskqueue [as 別名]
# 或者: from google.appengine.api.taskqueue import Task [as 別名]
def decode_payload(cls, request):
"""Decode task payload.
HugeTask controls its own payload entirely including urlencoding.
It doesn't depend on any particular web framework.
Args:
request: a webapp Request instance.
Returns:
A dict of str to str. The same as the params argument to __init__.
Raises:
DeprecationWarning: When task payload constructed from an older
incompatible version of mapreduce.
"""
# TODO(user): Pass mr_id into headers. Otherwise when payload decoding
# failed, we can't abort a mr.
if request.headers.get(cls.PAYLOAD_VERSION_HEADER) != cls.PAYLOAD_VERSION:
raise DeprecationWarning(
"Task is generated by an older incompatible version of mapreduce. "
"Please kill this job manually")
return cls._decode_payload(request.body)
示例7: _check_mr_state
# 需要導入模塊: from google.appengine.api import taskqueue [as 別名]
# 或者: from google.appengine.api.taskqueue import Task [as 別名]
def _check_mr_state(cls, state, mr_id):
"""Check MapreduceState.
Args:
state: an MapreduceState instance.
mr_id: mapreduce id.
Returns:
True if state is valid. False if not and this task should be dropped.
"""
if state is None:
logging.warning(
"Mapreduce State for job %s is missing. Dropping Task.",
mr_id)
return False
if not state.active:
logging.warning(
"Mapreduce %s is not active. Looks like spurious task "
"execution. Dropping Task.", mr_id)
return False
return True
示例8: _add_kickoff_task
# 需要導入模塊: from google.appengine.api import taskqueue [as 別名]
# 或者: from google.appengine.api.taskqueue import Task [as 別名]
def _add_kickoff_task(cls,
base_path,
mapreduce_spec,
eta,
countdown,
queue_name):
"""Enqueues a new kickoff task."""
params = {"mapreduce_id": mapreduce_spec.mapreduce_id}
# Task is not named so that it can be added within a transaction.
kickoff_task = taskqueue.Task(
url=base_path + "/kickoffjob_callback/" + mapreduce_spec.mapreduce_id,
headers=util._get_task_headers(mapreduce_spec.mapreduce_id),
params=params,
eta=eta,
countdown=countdown)
hooks = mapreduce_spec.get_hooks()
if hooks is not None:
try:
hooks.enqueue_kickoff_task(kickoff_task, queue_name)
return
except NotImplementedError:
pass
kickoff_task.add(queue_name, transactional=True)
示例9: schedule
# 需要導入模塊: from google.appengine.api import taskqueue [as 別名]
# 或者: from google.appengine.api.taskqueue import Task [as 別名]
def schedule(cls, mapreduce_spec):
"""Schedule finalize task.
Args:
mapreduce_spec: mapreduce specification as MapreduceSpec.
"""
task_name = mapreduce_spec.mapreduce_id + "-finalize"
finalize_task = taskqueue.Task(
name=task_name,
url=(mapreduce_spec.params["base_path"] + "/finalizejob_callback/" +
mapreduce_spec.mapreduce_id),
params={"mapreduce_id": mapreduce_spec.mapreduce_id},
headers=util._get_task_headers(mapreduce_spec.mapreduce_id))
queue_name = util.get_queue_name(None)
if not _run_task_hook(mapreduce_spec.get_hooks(),
"enqueue_controller_task",
finalize_task,
queue_name):
try:
finalize_task.add(queue_name)
except (taskqueue.TombstonedTaskError,
taskqueue.TaskAlreadyExistsError), e:
logging.warning("Task %r already exists. %s: %s",
task_name, e.__class__, e)
示例10: post
# 需要導入模塊: from google.appengine.api import taskqueue [as 別名]
# 或者: from google.appengine.api.taskqueue import Task [as 別名]
def post(self):
file_info = self.get_file_infos()[0]
#for i in dir(file_info):
# if not '__' in i:
# logging.info('%s is %s' % (i, getattr(file_info, i)))
task = ImportTask(
uploaded_file = file_info.gs_object_name
)
task.put()
retry_options = taskqueue.TaskRetryOptions(task_retry_limit=0)
queue_task = taskqueue.Task(url='/import', params={"task":task.key.urlsafe()}, retry_options=retry_options)
queue_task.add()
result = {"message" : "Upload finished, starting import...", "id" : task.key.urlsafe()}
self.response.headers['Content-Type'] = "application/json"
self.response.write(json.dumps(result))
示例11: _CreateNewTask
# 需要導入模塊: from google.appengine.api import taskqueue [as 別名]
# 或者: from google.appengine.api.taskqueue import Task [as 別名]
def _CreateNewTask(self, owner_email, message_criteria):
"""Helper to create new task db entity and related Task for the backend.
If the master task fails creation in the db, the error will be raised
for the user to view.
If the master task fails to be enqueued, the task state is updated to
ABORTED.
Args:
owner_email: String email address of the user. Used in authorization.
message_criteria: String criteria used to find message(s) to recall.
Returns:
Urlsafe (String) key for the RecallTaskModel entity that was created.
"""
recall_task_entity = recall_task.RecallTaskModel(
owner_email=owner_email,
message_criteria=message_criteria)
recall_task_key = recall_task_entity.put()
self._EnqueueMasterRecallTask(owner_email=owner_email,
message_criteria=message_criteria,
task_key_id=recall_task_key.id())
return recall_task_key.urlsafe()
示例12: get
# 需要導入模塊: from google.appengine.api import taskqueue [as 別名]
# 或者: from google.appengine.api.taskqueue import Task [as 別名]
def get(self, task_key_urlsafe): # pylint: disable=g-bad-name
"""Handler for /task/debug get requests.
Args:
task_key_urlsafe: String representation of task key safe for urls.
"""
_PreventUnauthorizedAccess()
task = recall_task.RecallTaskModel.FetchTaskFromSafeId(
user_domain=view_utils.GetUserDomain(_SafelyGetCurrentUserEmail()),
task_key_urlsafe=task_key_urlsafe)
task_key_id = task.key.id() if task else 0
counter_tuples = [
('User Retrieval Tasks Started (Expected)',
sharded_counter.GetCounterCount(
view_utils.MakeRetrievalStartedCounterName(task_key_id))),
('User Retrieval Tasks Ended (Actual)',
sharded_counter.GetCounterCount(
view_utils.MakeRetrievalEndedCounterName(task_key_id))),
('Task Backend Errors (Automatically Retried)',
sharded_counter.GetCounterCount(
view_utils.MakeBackendErrorCounterName(task_key_id)))]
self._WriteTemplate(template_file='debug_task',
tpl_counter_tuples=counter_tuples, tpl_task=task)
示例13: _AddUserRetrievalTask
# 需要導入模塊: from google.appengine.api import taskqueue [as 別名]
# 或者: from google.appengine.api.taskqueue import Task [as 別名]
def _AddUserRetrievalTask(self, task):
"""Helper to transactionally add the tasks.
Do not set transactional=True in the Task because Push Queues have a
5 Task per add limit when transactional=True per:
http://developers.google.com/appengine/docs/python/taskqueue/overview-push
Args:
task: Task or list of Tasks to retrieve domain users.
Raises:
re-raises any taskqueue errors raised.
"""
try:
Queue('retrieve-users-queue').add(task=task)
except TaskQueueError:
view_utils.FailRecallTask(
task_key_id=self._task_key_id,
reason_string='Failed to enqueue retrieve users tasks.')
raise
示例14: post
# 需要導入模塊: from google.appengine.api import taskqueue [as 別名]
# 或者: from google.appengine.api.taskqueue import Task [as 別名]
def post(self):
amount = int(self.request.get('amount'))
task = taskqueue.add(
url='/update_counter',
target='worker',
params={'amount': amount})
self.response.write(
'Task {} enqueued, ETA {}.'.format(task.name, task.eta))
# AsyncEnqueueTaskHandler behaves the same as EnqueueTaskHandler, but shows
# how to queue the task using the asyncronous API. This is not wired up by
# default. To use this, change the MainPageHandler's form action to
# /enqueue_async
示例15: run_from_request
# 需要導入模塊: from google.appengine.api import taskqueue [as 別名]
# 或者: from google.appengine.api.taskqueue import Task [as 別名]
def run_from_request(self):
"""Default behavior for POST requests to deferred handler."""
if "X-AppEngine-TaskName" not in self.request.headers:
logging.error("Detected an attempted XSRF attack. The header "
'"X-AppEngine-Taskname" was not set.')
self.response.set_status(403)
return
in_prod = (
not self.request.environ.get("SERVER_SOFTWARE").startswith("Devel"))
if in_prod and self.request.environ.get("REMOTE_ADDR") != "0.1.0.2":
logging.error("Detected an attempted XSRF attack. This request did "
"not originate from Task Queue.")
self.response.set_status(403)
return
headers = ["%s:%s" % (k, v) for k, v in self.request.headers.items()
if k.lower().startswith("x-appengine-")]
logging.log(_DEFAULT_LOG_LEVEL, ", ".join(headers))
run(self.request.body)