当前位置: 首页>>代码示例>>Python>>正文


Python Task.json_safe_dict方法代码示例

本文整理汇总了Python中task.Task.json_safe_dict方法的典型用法代码示例。如果您正苦于以下问题:Python Task.json_safe_dict方法的具体用法?Python Task.json_safe_dict怎么用?Python Task.json_safe_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在task.Task的用法示例。


在下文中一共展示了Task.json_safe_dict方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get

# 需要导入模块: from task import Task [as 别名]
# 或者: from task.Task import json_safe_dict [as 别名]
  def get(self, project, queue, task):
    """ Get the named task in a queue.

    Args:
      project: A string containing an application ID.
      queue: A string containing a queue name.
      task: A string containing a task ID.
    """
    task = Task({'id': task, 'queueName': queue})

    requested_fields = self.get_argument('fields', None)
    if requested_fields is None:
      fields = TASK_FIELDS
    else:
      fields = parse_fields(requested_fields)

    omit_payload = False
    if 'payloadBase64' not in fields:
      omit_payload = True

    queue = self.queue_handler.get_queue(project, queue)
    if queue is None:
      write_error(self, HTTPCodes.NOT_FOUND, 'Queue not found.')
      return

    task = queue.get_task(task, omit_payload=omit_payload)
    self.write(json.dumps(task.json_safe_dict(fields=fields)))
开发者ID:,项目名称:,代码行数:29,代码来源:

示例2: post

# 需要导入模块: from task import Task [as 别名]
# 或者: from task.Task import json_safe_dict [as 别名]
  def post(self, project, queue):
    """ Insert a task into an existing queue.

    Args:
      project: A string containing an application ID.
      queue: A string containing a queue name.
    """
    try:
      task_info = tornado.escape.json_decode(self.request.body)
    except ValueError:
      write_error(self, HTTPCodes.BAD_REQUEST,
                  'The request body must contain a task.')
      return

    if 'payloadBase64' not in task_info:
      write_error(self, HTTPCodes.BAD_REQUEST,
                  'payloadBase64 must be specified.')
      return

    if not BASE64_CHARS_RE.match(task_info['payloadBase64']):
      write_error(self, HTTPCodes.BAD_REQUEST,
                  'Invalid payloadBase64 value.')
      return

    try:
      task = Task(task_info)
    except TypeError:
      write_error(self, HTTPCodes.BAD_REQUEST, 'Invalid payloadBase64 value.')
      return

    requested_fields = self.get_argument('fields', None)
    if requested_fields is None:
      fields = TASK_FIELDS
    else:
      fields = parse_fields(requested_fields)

    queue = self.queue_handler.get_queue(project, queue)
    if queue is None:
      write_error(self, HTTPCodes.NOT_FOUND, 'Queue not found.')
      return

    try:
      queue.add_task(task)
    except InvalidTaskInfo as insert_error:
      write_error(self, HTTPCodes.BAD_REQUEST, insert_error.message)
      return

    self.write(json.dumps(task.json_safe_dict(fields=fields)))
开发者ID:,项目名称:,代码行数:50,代码来源:


注:本文中的task.Task.json_safe_dict方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。