def __init__(self): super(SleepyElder, self).__init__() self._lair = ActorRegistry.get_by_class_name('SpiderLair')[0] self._lair_command = { 'command': 'kick_all', 'data': None } self._work = True
def test_actors_may_be_looked_up_by_class_name(actor_a_class, a_actor_refs, b_actor_refs): result = ActorRegistry.get_by_class_name('ActorA') for a_actor in a_actor_refs: assert a_actor in result for b_actor in b_actor_refs: assert b_actor not in result
def test_actors_may_be_looked_up_by_class_name( actor_a_class, a_actor_refs, b_actor_refs ): result = ActorRegistry.get_by_class_name('ActorA') for a_actor in a_actor_refs: assert a_actor in result for b_actor in b_actor_refs: assert b_actor not in result
def test_register_get_by_filter(actor_class): actor_ref = actor_class().start() # 已经完成注册啦了. # step1 测试 urn查询 assert ActorRegistry.get_by_urn(actor_ref.actor_urn) == actor_ref # step2 测试类名查询 assert ActorRegistry.get_by_class(actor_ref.actor_class)[0] == actor_ref # # step3 测试类名字符查询 assert ActorRegistry.get_by_class_name( 'CustomThreadingActor')[0] == actor_ref ActorRegistry.stop_all()
def spider_info(spider_name): spider = ActorRegistry.get_by_class_name('SpiderLair')[0].ask({ 'command': 'get_spider_by_name', 'data': spider_name }) if spider: spider_info_result = spider.ask({ 'command': 'get_settings_and_info' }) return jsonify(spider_info_result) return jsonify({ 'result': '500', 'message': 'No spider with this name' })
def spider_list(): spiders = ActorRegistry.get_by_class_name('SpiderLair')[0].ask({ 'command': 'get_all_spiders' }) result = [] for spider in spiders: info = spider.ask({ 'command': 'get_info' }) if info: if info.get('image_url'): info['image_url'] = url_for('static', filename=info['image_url']) result.append(info) return jsonify({ 'spiders_info': result })
def test_actors_may_be_looked_up_by_class_name(self): result = ActorRegistry.get_by_class_name('AnActor') for a_actor in self.a_actors: self.assert_(a_actor in result) for b_actor in self.b_actors: self.assert_(b_actor not in result)
def test_actors_may_be_looked_up_by_class_name(self): result = ActorRegistry.get_by_class_name('AnActor') for a_actor in self.a_actors: self.assertTrue(a_actor in result) for b_actor in self.b_actors: self.assertTrue(b_actor not in result)
def run_all(): ActorRegistry.get_by_class_name('SpiderLair')[0].tell({ 'command': 'kick_all' }) return jsonify({'result': 'ok'})