當前位置: 首頁>>代碼示例>>Python>>正文


Python taskqueue.add方法代碼示例

本文整理匯總了Python中google.appengine.api.taskqueue.add方法的典型用法代碼示例。如果您正苦於以下問題:Python taskqueue.add方法的具體用法?Python taskqueue.add怎麽用?Python taskqueue.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在google.appengine.api.taskqueue的用法示例。


在下文中一共展示了taskqueue.add方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: stream_to_bq

# 需要導入模塊: from google.appengine.api import taskqueue [as 別名]
# 或者: from google.appengine.api.taskqueue import add [as 別名]
def stream_to_bq(self, user, summary, timestamp=None):
    """Creates a task to stream an update to BigQuery.

    Args:
      user: string user email of the acting user.
      summary: string summary of the action being performed.
      timestamp: datetime, if not provided current time will be used.
    """
    if not timestamp:
      timestamp = datetime.datetime.utcnow()
    calling_function = inspect.stack()[1][3]
    task_params = {
        'model_instance': self,
        'timestamp': timestamp,
        'actor': user,
        'method': calling_function,
        'summary': summary,
    }
    taskqueue.add(
        queue_name='stream-bq',
        payload=pickle.dumps(task_params),
        target='default') 
開發者ID:google,項目名稱:loaner,代碼行數:24,代碼來源:base_model.py

示例2: add_docs_to_index

# 需要導入模塊: from google.appengine.api import taskqueue [as 別名]
# 或者: from google.appengine.api.taskqueue import add [as 別名]
def add_docs_to_index(cls, documents):
    """Adds a list of documents to a particular index.

    Args:
      documents: a list of search.Documents to add to the class' index.
    """
    index = cls.get_index()
    for doc in documents:
      try:
        index.put(doc)
      except search.PutError as err:
        result = err.results[0]
        if result.code == search.OperationResult.TRANSIENT_ERROR:
          index.put(doc)
      except (search.Error, apiproxy_errors.OverQuotaError):
        logging.error(_PUT_DOC_ERR_MSG, doc, index) 
開發者ID:google,項目名稱:loaner,代碼行數:18,代碼來源:base_model.py

示例3: _send_email

# 需要導入模塊: from google.appengine.api import taskqueue [as 別名]
# 或者: from google.appengine.api.taskqueue import add [as 別名]
def _send_email(**kwargs):
  """Sends email using App Engine's email API.

  Args:
    **kwargs: kwargs for the email api.
  """
  kwargs['sender'] = constants.SEND_EMAIL_AS
  if not constants.ON_PROD:
    if constants.ON_DEV:
      kwargs['subject'] = '[dev] ' + kwargs['subject']
    elif constants.ON_LOCAL:
      kwargs['subject'] = '[local] ' + kwargs['subject']
    elif constants.ON_QA:
      kwargs['subject'] = '[qa] ' + kwargs['subject']

  taskqueue.add(queue_name='send-email', params=kwargs, target='default') 
開發者ID:google,項目名稱:loaner,代碼行數:18,代碼來源:send_email.py

示例4: get_actions_for_event

# 需要導入模塊: from google.appengine.api import taskqueue [as 別名]
# 或者: from google.appengine.api.taskqueue import add [as 別名]
def get_actions_for_event(event_name):
  """Gets all Action mappings for a given Event.

  Args:
    event_name: str, the name of the Event.

  Returns:
    A list of actions for the Event, or None.

  Raises:
    NoEventsError: if there are no Events to be found in datastore.
  """
  all_mappings = get_all_event_action_mappings()
  if not all_mappings:
    raise NoEventsError(
        'There are no events; run bootstrap to add the default ones.')

  return all_mappings.get(event_name) 
開發者ID:google,項目名稱:loaner,代碼行數:20,代碼來源:events.py

示例5: post

# 需要導入模塊: from google.appengine.api import taskqueue [as 別名]
# 或者: from google.appengine.api.taskqueue import add [as 別名]
def post(self):
        filename = self.request.get("filename")
        blob_key = self.request.get("blobkey")
        ds_key   = self.request.get("ds_key")
        output_link   = self.request.get("output_link")

        if self.request.get("run_lsh"):
            taskqueue.add(url='/test_zip_worker', 
                          params={'filename': filename,
                                  'blob_key': blob_key,
                                  })
        else:
            pass

        time.sleep(1)
        self.get() 
開發者ID:singhj,項目名稱:locality-sensitive-hashing,代碼行數:18,代碼來源:test_db_datastore.py

示例6: add_to_queue

# 需要導入模塊: from google.appengine.api import taskqueue [as 別名]
# 或者: from google.appengine.api.taskqueue import add [as 別名]
def add_to_queue(self, url=None, target_state='queued', countdown=0):
        """
        Adds job to task queue and transactionally updates state to 'queued'
        and saves job.
        Does nothing if state is not 'scheduled'.
        """
        if self.state != 'scheduled':
            logging.warn('tried to add job {} with state {}, to queue, '
                         'doing nothing'.format(self.key, self.state))
            return
        if url is None:
            url = self.queue_url
        logging.debug(u'scheduling job {} for {}'.format(self.key,
                                                        self.user_email))
        taskqueue.add(url=url,
                      payload=json.dumps({'key': self.key.urlsafe()}),
                      queue_name=self.queue_name,
                      countdown=countdown,
                      transactional=True)
        self.state = target_state
        self.put() 
開發者ID:Schibum,項目名稱:sndlatr,代碼行數:23,代碼來源:models.py

示例7: get

# 需要導入模塊: from google.appengine.api import taskqueue [as 別名]
# 或者: from google.appengine.api.taskqueue import add [as 別名]
def get(self, namespace='default'):
        # Queue task to update global counter.
        current_global_count = get_count('counter')
        taskqueue.add(
            url='/tasks/counter',
            params={'counter_name': 'counter'})

        # Queue task to update counter in specified namespace.
        previous_namespace = namespace_manager.get_namespace()
        try:
            namespace_manager.set_namespace(namespace)
            current_namespace_count = get_count('counter')
            taskqueue.add(
                url='/tasks/counter',
                params={'counter_name': 'counter'})
        finally:
            namespace_manager.set_namespace(previous_namespace)

        self.response.write(
            'Counters will be updated asyncronously.'
            'Current values: Global: {}, Namespace {}: {}'.format(
                current_global_count, namespace, current_namespace_count)) 
開發者ID:GoogleCloudPlatform,項目名稱:python-docs-samples,代碼行數:24,代碼來源:taskqueue.py

示例8: post

# 需要導入模塊: from google.appengine.api import taskqueue [as 別名]
# 或者: from google.appengine.api.taskqueue import add [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 
開發者ID:GoogleCloudPlatform,項目名稱:python-docs-samples,代碼行數:18,代碼來源:application.py

示例9: enqueue_process_change_task

# 需要導入模塊: from google.appengine.api import taskqueue [as 別名]
# 或者: from google.appengine.api.taskqueue import add [as 別名]
def enqueue_process_change_task(auth_db_rev):
  """Transactionally adds a call to 'process_change' to the task queue.

  Pins the task to currently executing version of BACKEND_MODULE module
  (defined in config.py).

  Added as AuthDB commit callback in get_backend_routes() below.
  """
  assert ndb.in_transaction()
  conf = config.ensure_configured()
  try:
    # Pin the task to the module and version.
    taskqueue.add(
        url='/internal/auth/taskqueue/process-change/%d' % auth_db_rev,
        queue_name=conf.PROCESS_CHANGE_TASK_QUEUE,
        headers={'Host': modules.get_hostname(module=conf.BACKEND_MODULE)},
        transactional=True)
  except Exception as e:
    logging.error(
        'Problem adding "process-change" task to the task queue (%s): %s',
        e.__class__.__name__, e)
    raise 
開發者ID:luci,項目名稱:luci-py,代碼行數:24,代碼來源:change_log.py

示例10: _send_love

# 需要導入模塊: from google.appengine.api import taskqueue [as 別名]
# 或者: from google.appengine.api.taskqueue import add [as 別名]
def _send_love(recipient_key, message, sender_key, secret):
    """Send love and do associated bookkeeping."""
    new_love = Love(
        sender_key=sender_key,
        recipient_key=recipient_key,
        message=message,
        secret=(secret is True),
    )
    new_love.put()
    LoveCount.update(new_love)

    # Send email asynchronously
    taskqueue.add(
        url='/tasks/love/email',
        params={
            'id': new_love.key.id()
        }
    )

    if not secret:
        logic.event.add_event(
            logic.event.LOVESENT,
            {'love_id': new_love.key.id()},
        ) 
開發者ID:Yelp,項目名稱:love,代碼行數:26,代碼來源:love.py

示例11: post

# 需要導入模塊: from google.appengine.api import taskqueue [as 別名]
# 或者: from google.appengine.api.taskqueue import add [as 別名]
def post(self):
        """Create the new member.
        '409 Conflict' is thrown if the email address is already associated
        with an existing member.
        """
        helpers.check_csrf(self.request)

        user = users.get_current_user()
        if not user or not gapps.is_user_authorized(user):
            detail = 'user not authorized' if user else 'user not logged in'
            webapp2.abort(401, detail=detail)

        new_member = gapps.member_dict_from_request(self.request,
                                                    user.email(),
                                                    'join')
        join_or_renew = gapps.join_or_renew_member_from_dict(new_member)

        self.response.write('success: %s' % join_or_renew)

        # Queue the welcome email
        taskqueue.add(url='/tasks/new-member-mail', params=new_member) 
開發者ID:adam-p,項目名稱:danforth-east,代碼行數:23,代碼來源:main.py

示例12: get

# 需要導入模塊: from google.appengine.api import taskqueue [as 別名]
# 或者: from google.appengine.api.taskqueue import add [as 別名]
def get(self):
    """Handler for doing metrics fan-in for all projects."""

    # Can only be accessed by cron.
    if self.request.headers.get('X-Appengine-Cron') is None:
      self.error(403)
      return

    metrics.create_custom_metrics(config.PROJECT_ID)
    date_string = helpers.date_object_to_rfc3339(datetime.now())

    for src_project in metrics.get_projects(config.BILLING_ACCOUNT):
      taskqueue.add(
          queue_name='copy-metrics',
          name=filter(str.isalnum, '%s%s' % (src_project, date_string)),
          url='/CopyMetrics',
          method='GET',
          params={
              'src_project': src_project,
              'dst_project': config.PROJECT_ID,
          }) 
開發者ID:GoogleCloudPlatform,項目名稱:professional-services,代碼行數:23,代碼來源:main.py

示例13: post

# 需要導入模塊: from google.appengine.api import taskqueue [as 別名]
# 或者: from google.appengine.api.taskqueue import add [as 別名]
def post(self):  # pylint:disable-msg=invalid-name,missing-docstring
    assert self.request.environ[common.HTTP_X_APPENGINE_QUEUENAME]
    query = model.Project.query(namespace=settings.PLAYGROUND_NAMESPACE)
    cursor = self.request.get('cursor', None)
    if cursor:
      cursor = Cursor(urlsafe=cursor)
    projects, next_cursor, more = query.fetch_page(_CURSOR_PAGE_SIZE,
                                                   start_cursor=cursor)
    if more and next_cursor:
      taskqueue.add(queue_name='fixit',
                    url='/playground/fix/project',
                    params={'cursor': next_cursor.urlsafe()})
    for project in projects:
      FixProject(project)
    if not next_cursor:
      shared.w('REACHED END OF QUERY CURSOR, '
               'ALTHOUGH OTHER TASKS MAY STILL BE EXECUTING') 
開發者ID:googlearchive,項目名稱:cloud-playground,代碼行數:19,代碼來源:fixit.py

示例14: test_task_rescheduling

# 需要導入模塊: from google.appengine.api import taskqueue [as 別名]
# 或者: from google.appengine.api.taskqueue import add [as 別名]
def test_task_rescheduling(self):
        """Tests that task is rescheduled for continuation."""
        tq_mock = mox.Mox()
        tq_mock.StubOutWithMock(taskqueue, 'add')
        taskqueue.add(name=mox.IsA(unicode),
                      method='POST',
                      url='/haiti/tasks/process_expirations',
                      queue_name='expiry',
                      params={'cursor': ''})
        tq_mock.ReplayAll()
        # DeadlineExceededErrors can be raised at any time. A convenient way for
        # us to raise it during this test execution is with utils.get_utcnow.
        with mock.patch('utils.get_utcnow') as get_utcnow_mock:
            get_utcnow_mock.side_effect = runtime.DeadlineExceededError()
            self.run_task('/haiti/tasks/process_expirations', method='POST')
        tq_mock.VerifyAll()
        tq_mock.UnsetStubs() 
開發者ID:google,項目名稱:personfinder,代碼行數:19,代碼來源:test_deletion.py

示例15: _test_deadline_exceeded

# 需要導入模塊: from google.appengine.api import taskqueue [as 別名]
# 或者: from google.appengine.api.taskqueue import add [as 別名]
def _test_deadline_exceeded(run_task_func, task_url):
    mox_obj = mox.Mox()
    mox_obj.StubOutWithMock(taskqueue, 'add')
    taskqueue.add(
        method='POST',
        url=task_url,
        params={'cursor': None},
        queue_name='datachecks',
        retry_options=mox.IsA(taskqueue.taskqueue.TaskRetryOptions),
        name=mox.IsA(unicode))
    mox_obj.ReplayAll()
    with mock.patch('utils.validate_email') as mock_validate_email:
        mock_validate_email.side_effect = deadline_exceeded_side_effect
        run_task_func()
    mox_obj.VerifyAll()
    mox_obj.UnsetStubs() 
開發者ID:google,項目名稱:personfinder,代碼行數:18,代碼來源:test_datachecks.py


注:本文中的google.appengine.api.taskqueue.add方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。