本文整理汇总了Python中worker.Worker.returns_queue方法的典型用法代码示例。如果您正苦于以下问题:Python Worker.returns_queue方法的具体用法?Python Worker.returns_queue怎么用?Python Worker.returns_queue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类worker.Worker
的用法示例。
在下文中一共展示了Worker.returns_queue方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_notification_timeout
# 需要导入模块: from worker import Worker [as 别名]
# 或者: from worker.Worker import returns_queue [as 别名]
def test_notification_timeout(self):
if os.name == 'nt':
return
# These queues connect a poller/reactionner with a worker
to_queue = Queue()
manager = Manager()
from_queue = manager.list()
control_queue = Queue()
# This testscript plays the role of the reactionner
# Now "fork" a worker
w = Worker(1,to_queue,from_queue,1)
w.id = 1
w.i_am_dying = False
# We prepare a notification in the to_queue
c = Contact()
c.contact_name = "mr.schinken"
n = Notification('PROBLEM', 'scheduled', 'libexec/sleep_command.sh 7', '', Service(), '', '', id=1)
n.status = "queue"
#n.command = "libexec/sleep_command.sh 7"
n.t_to_go = time.time()
n.contact = c
n.timeout = 2
n.env = {}
n.exit_status = 0
n.module_type = "fork"
nn = n.copy_shell()
# Send the job to the worker
msg = Message(id=0, type='Do', data=nn)
to_queue.put(msg)
w.checks = []
w.returns_queue = from_queue
w.s = to_queue
w.c = control_queue
# Now we simulate the Worker's work() routine. We can't call it
# as w.work() because it is an endless loop
for i in xrange(1,10):
w.get_new_checks()
# During the first loop the sleeping command is launched
w.launch_new_checks()
w.manage_finished_checks()
time.sleep(1)
# The worker should have finished it's job now, either correctly or
# with a timeout
o = from_queue.pop()
self.assert_(o.status == 'timeout')
self.assert_(o.exit_status == 3)
self.assert_(o.execution_time < n.timeout+1)
# Be a good poller and clean up.
to_queue.close()
control_queue.close()
# Now look what the scheduler says to all this
self.sched.actions[n.id] = n
self.sched.put_results(o)
self.assert_(self.any_log_match("Warning: Contact mr.schinken service notification command 'libexec/sleep_command.sh 7 ' timed out after 2 seconds"))