def worker(change_request: dict) -> None: """Process incoming change requests Args: change_request: dict<ChangeRequest> {contract_id: string, action: SchedulerActions enum, seconds?:int, cron?: string} """ _log.debug(f"Change Request: {change_request}") contract_id = change_request["contract_id"] action = change_request["action"] seconds = change_request.get("seconds") cron = change_request.get("cron") txn_type = change_request["txn_type"] execution_order = change_request["execution_order"] # Delete jobs if action == "delete": if not timing_event.exists(contract_id): raise exceptions.TimingEventSchedulerError("NOT_FOUND") event = timing_event.get_by_id(contract_id) event.delete() # Update job if action == "update": if not timing_event.exists(contract_id): raise exceptions.TimingEventSchedulerError("NOT_FOUND") event = timing_event.get_by_id(contract_id) event.update(cron=cron, seconds=seconds, execution_order=execution_order, txn_type=txn_type) # Create new job if action == "create": event = timing_event.TimingEvent(cron=cron, seconds=seconds, timing_id=contract_id, execution_order=execution_order, txn_type=txn_type) event.start() _log.debug(f"Successful {action} on job '{contract_id}'")
def test_get_by_id_valid(self, hget): event = timing_event.get_by_id("id") self.assertIsInstance(event, timing_event.TimingEvent)
def test_get_by_id_fails(self, hget): try: timing_event.get_by_id("id") except Exception as e: self.assertEqual(str(e), "NOT_FOUND")