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


Python Task.unserialize方法代码示例

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


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

示例1: _dispatcher

# 需要导入模块: from task import Task [as 别名]
# 或者: from task.Task import unserialize [as 别名]
 def _dispatcher(self):
     http = httplib2.Http()
     while True:
         try:
             task = Task.unserialize(self.queue.get())
             timeout = gevent.Timeout(constants.WORKER_TIMEOUT)
             timeout.start()
             self.scheduler.send('start:%s\n' % task.id)
             
             if task.url.startswith('http'):
                 headers = {"User-Agent": "Miyamoto/0.1", "X-Task": task.id, "X-Queue": task.queue_name, "Content-type": "application/json"}
                 resp, content = http.request(task.url, method=task.method, headers=headers, body=task.params)
             else:
                 zmq_remotes = frozenset(task.url.split(','))
                 if not zmq_remotes in self.zmq_sockets:
                     sock = self.zmq.socket(zmq.REQ)
                     lock = gevent.coros.Semaphore()
                     for remote in zmq_remotes:
                         sock.connect(remote)
                     self.zmq_sockets[zmq_remotes] = (sock, lock)
                 else:
                     sock, lock = self.zmq_sockets[zmq_remotes]
                 try:
                     lock.acquire() # Because send/recv have to be done together
                     sock.send(task.url)
                     resp = sock.recv()
                 except zmq.ZMQError:
                     raise
                 finally:
                     lock.release()
             self.scheduler.send('success:%s\n' % task.id)
         except (gevent.Timeout, zmq.ZMQError, TaskFailure), e:
             self.scheduler.send('failure:%s:%s\n' % (task.id, str(e)))
         finally:
开发者ID:aliounedia,项目名称:miyamoto,代码行数:36,代码来源:dispatcher.py

示例2: _dispatcher

# 需要导入模块: from task import Task [as 别名]
# 或者: from task.Task import unserialize [as 别名]
 def _dispatcher(self):
     http = httplib2.Http()
     while True:
         try:
             task = Task.unserialize(self.queue.get())
             timeout = gevent.Timeout(constants.WORKER_TIMEOUT)
             timeout.start()
             self.scheduler.send('start:%s\n' % task.id)
             
             if task.url.startswith('http'):
                 headers = {"User-Agent": "Miyamoto/0.1", "X-Task": task.id, "X-Queue": task.queue_name, "Content-type": "application/json"}
                 resp, content = http.request(task.url, method=task.method, headers=headers, body=task.params)
                 if task.result_callback_url and content:
                     result_content_type = resp.get_header('Content-type')
                     result_data = content
                     if util.walks_like_json(result_content_type):
                         result_data = json.loads(content)
                     elif util.talks_like_form(result_content_type):
                         result_data = dict([(k,v[0]) for k,v in urlparse.parse_qs(content).items() ])
                     else:
                         try:
                             result_data = json.loads(content)
                         except Exception, e:
                             try:
                                 result_data = dict([(k,v[0]) for k,v in urlparse.parse_qs(content).items() ])
                             except Exception, e:
                                 pass
                     result_data.update({'status': resp.status, 'reason': resp.reason, 'headers': resp.getheaders()})
                     callback_resp, callback_content = http.request(task.result_callback_url, method='POST', body=json.dumps(result_data))
             else:
                 zmq_remotes = frozenset(task.url.split(','))
                 if not zmq_remotes in self.zmq_sockets:
                     sock = self.zmq.socket(zmq.REQ)
                     lock = gevent.coros.Semaphore()
                     for remote in zmq_remotes:
                         sock.connect(remote)
                     self.zmq_sockets[zmq_remotes] = (sock, lock)
                 else:
                     sock, lock = self.zmq_sockets[zmq_remotes]
                 try:
                     lock.acquire() # Because send/recv have to be done together
                     sock.send(task.url)
                     resp = sock.recv()
                 except zmq.ZMQError:
                     raise
                 finally:
                     lock.release()
             self.scheduler.send('success:%s\n' % task.id)
开发者ID:ewheeler,项目名称:miyamoto,代码行数:50,代码来源:dispatcher.py

示例3: _backend_server

# 需要导入模块: from task import Task [as 别名]
# 或者: from task.Task import unserialize [as 别名]
 def _backend_server(self, socket, address):
     for line in util.line_protocol(socket):
         action, payload = line.split(':', 1)
         
         if action == 'schedule':
             task = Task.unserialize(payload)
             task.schedule(self.dispatcher)
             self.scheduled[task.id] = task
             socket.send('scheduled:%s\n' % task.id)
             print "scheduled: %s" % task.id
         
         elif action == 'cancel':
             task_id = payload
             print "canceled: %s" % task_id
             self.scheduled.pop(task_id).cancel()
         
         elif action == 'reschedule':
             task_id, eta = payload.split(':', 1)
             eta = int(eta)
             print "rescheduled: %s for %s" % (task_id, eta)
             self.scheduled[task_id].reschedule(self.dispatcher, eta)
开发者ID:aliounedia,项目名称:miyamoto,代码行数:23,代码来源:scheduler.py


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