本文整理汇总了Python中celery.bin.multi.MultiTool.node_alive方法的典型用法代码示例。如果您正苦于以下问题:Python MultiTool.node_alive方法的具体用法?Python MultiTool.node_alive怎么用?Python MultiTool.node_alive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类celery.bin.multi.MultiTool
的用法示例。
在下文中一共展示了MultiTool.node_alive方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_MultiTool
# 需要导入模块: from celery.bin.multi import MultiTool [as 别名]
# 或者: from celery.bin.multi.MultiTool import node_alive [as 别名]
#.........这里部分代码省略.........
sorted(('celery worker', '--pidfile=foo.pid',
'-n [email protected]', '')),
)
self.assertEqual(node_0[2], 10)
self.assertEqual(node_1[0], '[email protected]')
self.assertEqual(
sorted(node_1[1]),
sorted(('celery worker', '--pidfile=bar.pid',
'-n [email protected]', '')),
)
self.assertEqual(node_1[2], 11)
self.assertTrue(callback.called)
cargs, _ = callback.call_args
self.assertEqual(cargs[0], '[email protected]')
self.assertItemsEqual(
cargs[1],
['celery worker', '--pidfile=baz.pid', '-n [email protected]', ''],
)
self.assertIsNone(cargs[2])
self.assertIn('DOWN', self.fh.getvalue())
# without callback, should work
nodes = self.t.getpids(p, 'celery worker', callback=None)
@patch('celery.bin.multi.Pidfile')
@patch('socket.gethostname')
@patch('celery.bin.multi.sleep')
def test_shutdown_nodes(self, slepp, gethostname, Pidfile):
gethostname.return_value = 'e.com'
self.prepare_pidfile_for_getpids(Pidfile)
self.assertIsNone(self.t.shutdown_nodes([]))
self.t.signal_node = Mock()
node_alive = self.t.node_alive = Mock()
self.t.node_alive.return_value = False
callback = Mock()
self.t.stop(['foo', 'bar', 'baz'], 'celery worker', callback=callback)
sigs = sorted(self.t.signal_node.call_args_list)
self.assertEqual(len(sigs), 2)
self.assertIn(
('[email protected]', 10, signal.SIGTERM),
[tup[0] for tup in sigs],
)
self.assertIn(
('[email protected]', 11, signal.SIGTERM),
[tup[0] for tup in sigs],
)
self.t.signal_node.return_value = False
self.assertTrue(callback.called)
self.t.stop(['foo', 'bar', 'baz'], 'celery worker', callback=None)
def on_node_alive(pid):
if node_alive.call_count > 4:
return True
return False
self.t.signal_node.return_value = True
self.t.node_alive.side_effect = on_node_alive
self.t.stop(['foo', 'bar', 'baz'], 'celery worker', retry=True)
@patch('os.kill')
def test_node_alive(self, kill):
kill.return_value = True
self.assertTrue(self.t.node_alive(13))
esrch = OSError()
esrch.errno = errno.ESRCH