def publish_create(cls, payload): try: if isinstance(payload, LiveActionDB): scheduler.get_scheduler().process(payload) except Exception: traceback.print_exc() print(payload)
def publish_state(cls, payload, state): try: if isinstance(payload, LiveActionDB): if state == action_constants.LIVEACTION_STATUS_REQUESTED: scheduler.get_scheduler().process(payload) else: worker.get_worker().process(payload) except Exception: traceback.print_exc() print(payload)
def test_disabled_policy_not_applied_on_pre_run(self, mock_policies): scheduler_worker = scheduler.get_scheduler() ########## # First test a scenario where policy is enabled ########## self.assertTrue(self.policy_db.enabled) # Post run hasn't been called yet, call count should be 0 self.assertEqual(mock_policies.get_driver.call_count, 0) liveaction = LiveActionDB(action='wolfpack.action-1', parameters={'actionstr': 'foo'}) live_action_db, execution_db = action_service.request(liveaction) scheduler_worker._apply_pre_run_policies(liveaction_db=live_action_db) # Ony policy has been applied so call count should be 1 self.assertEqual(mock_policies.get_driver.call_count, 1) ########## # Now a scenaro with disabled policy ########## mock_policies.get_driver.call_count = 0 self.policy_db.enabled = False self.policy_db = Policy.add_or_update(self.policy_db) self.assertFalse(self.policy_db.enabled) self.assertEqual(mock_policies.get_driver.call_count, 0) liveaction = LiveActionDB(action='wolfpack.action-1', parameters={'actionstr': 'foo'}) live_action_db, execution_db = action_service.request(liveaction) scheduler_worker._apply_pre_run_policies(liveaction_db=live_action_db) # Policy is disabled so call_count should stay the same as before as no policies have been # applied self.assertEqual(mock_policies.get_driver.call_count, 0)
def _run_worker(): LOG.info('(PID=%s) Worker started.', os.getpid()) components = [ scheduler.get_scheduler(), worker.get_worker() ] try: for component in components: component.start() for component in components: component.wait() except (KeyboardInterrupt, SystemExit): LOG.info('(PID=%s) Worker stopped.', os.getpid()) errors = False for component in components: try: component.shutdown() except: LOG.exception('Unable to shutdown %s.', component.__class__.__name__) errors = True if errors: return 1 except: LOG.exception('(PID=%s) Worker unexpectedly stopped.', os.getpid()) return 1 return 0
def publish_create(cls, payload): try: if isinstance(payload, LiveActionDB): thread = eventlet.spawn(scheduler.get_scheduler().process, payload) cls.threads.append(thread) except Exception: traceback.print_exc() print(payload)
def publish_state(cls, payload, state): try: if isinstance(payload, LiveActionDB): if state == action_constants.LIVEACTION_STATUS_REQUESTED: thread = eventlet.spawn(scheduler.get_scheduler().process, payload) cls.threads.append(thread) else: thread = eventlet.spawn(worker.get_worker().process, payload) cls.threads.append(thread) except Exception: traceback.print_exc() print(payload)
def __init__(self, *args, **kwargs): super(QueueConsumerTest, self).__init__(*args, **kwargs) self.scheduler = scheduler.get_scheduler() self.dispatcher = worker.get_worker()