def handle(self, *args, **options): if not options["task_code"]: log.error("Expected a task_code argument, use --help.") return numeric_level = getattr(logging, options["log_level"].upper(), None) if not isinstance(numeric_level, int): log.error("Invalid log level: %s" % options["log_level"]) numeric_level = 10 broker = BrokerConnection() connection = broker.connect_to_broker() removeFileHandlers() setFileHandler(options["worker_nr"]) setLevelToAllHandlers(numeric_level) if connection is None: log.error("Could not connect to broker.") return action = ActionTask(options["task_code"], options["worker_nr"]) logging.handlers.AMQPMessageHandler = AMQPMessageHandler broker_logging_handler = logging.handlers.AMQPMessageHandler( action, numeric_level) action.set_broker_logging_handler(broker_logging_handler) task_worker = Worker(connection, options["task_code"], action, options["worker_nr"]) task_worker.run_worker() removeFileHandlers()
def start_heartbeat(log_level='INFO'): """ Publish a message to execute a separate task. """ numeric_level = getattr(logging, log_level.upper(), None) broker = BrokerConnection() connection = broker.connect_to_broker() if connection is None: log.error("Could not connect to broker.") return action = ActionHeartbeat(connection, settings.HEARTBEAT_QUEUES) logging.handlers.AMQPMessageHandler = AMQPMessageHandler broker_handler = logging.handlers.AMQPMessageHandler(action, numeric_level) action.set_broker_logging_handler(broker_handler) success = action.perform() if connection.is_open: connection.close() return success
def start_workflow(scenario_id, workflowtemplate_id, log_level='INFO'): """ Opens connection to broker. Creates ActionWorkflow object. Creates logging handler to send loggings to broker. Sets logging handler to ActionWorkflow object. Performs workflow. Closes connection. """ numeric_level = getattr(logging, log_level.upper(), None) if not isinstance(numeric_level, int): log.error("Invalid log level: %s" % log_level) numeric_level = 10 broker = BrokerConnection() connection = broker.connect_to_broker() if connection is None: log.error("Could not connect to broker.") return action = ActionWorkflow( connection, scenario_id, workflowtemplate_id) logging.handlers.AMQPMessageHandler = AMQPMessageHandler broker_handler = logging.handlers.AMQPMessageHandler(action, numeric_level) action.set_broker_logging_handler(broker_handler) status = action.perform_workflow() if connection.is_open: connection.close() return status
def start_task(task_id, log_level='INFO'): """ Publish a message to execute a separate task. """ task = WorkflowTask.objects.get(pk=task_id) numeric_level = getattr(logging, log_level.upper(), None) if not isinstance(numeric_level, int): log.error("Invalid log level: %s" % log_level) numeric_level = 10 broker = BrokerConnection() connection = broker.connect_to_broker() if connection is None: log.error("Could not connect to broker.") return action = ActionTaskPublisher(connection, task) logging.handlers.AMQPMessageHandler = AMQPMessageHandler broker_handler = logging.handlers.AMQPMessageHandler(action, numeric_level) action.set_broker_logging_handler(broker_handler) success = action.perform() if connection.is_open: connection.close() return success
def handle(self, *args, **options): """ Open connection to broker. Creates message. Creates logging handler to send loggings to broker. Sets logging handler to ActionWorkflow object. Close connection. """ numeric_level = getattr(logging, options["log_level"].upper(), None) if not isinstance(numeric_level, int): log.error("Invalid log level: %s" % options["log_level"]) numeric_level = 10 broker = BrokerConnection() connection = broker.connect_to_broker() removeFileHandlers() setFileHandler("start") if connection is None: log.error("Could not connect to broker.") return action = ActionWorker( connection, options["worker_nr"], options["command"], options["task_code"], options["queue_code"] ) logging.handlers.AMQPMessageHandler = AMQPMessageHandler broker_handler = logging.handlers.AMQPMessageHandler(action, numeric_level) action.set_broker_logging_handler(broker_handler) action.execute() if connection.is_open: connection.close()
def start_workflow(scenario_id, workflowtemplate_id, log_level='INFO'): """ Opens connection to broker. Creates ActionWorkflow object. Creates logging handler to send loggings to broker. Sets logging handler to ActionWorkflow object. Performs workflow. Closes connection. """ numeric_level = getattr(logging, log_level.upper(), None) if not isinstance(numeric_level, int): log.error("Invalid log level: %s" % log_level) numeric_level = 10 broker = BrokerConnection() connection = broker.connect_to_broker() if connection is None: log.error("Could not connect to broker.") return action = ActionWorkflow(connection, scenario_id, workflowtemplate_id) logging.handlers.AMQPMessageHandler = AMQPMessageHandler broker_handler = logging.handlers.AMQPMessageHandler(action, numeric_level) action.set_broker_logging_handler(broker_handler) status = action.perform_workflow() if connection.is_open: connection.close() return status
def handle(self, *args, **options): broker = BrokerConnection() connection = broker.connect_to_broker() removeFileHandlers() setFileHandler('logging') if connection is None: log.error("Could not connect to broker.") return action = ActionLogging() logging_worker = Worker(connection, options["task_code"], action) logging_worker.run_worker()
def handle(self, *args, **options): numeric_level = getattr(logging, options["log_level"].upper(), None) if not isinstance(numeric_level, int): log.error("Invalid log level: %s" % options["log_level"]) numeric_level = 10 broker = BrokerConnection() connection = broker.connect_to_broker() removeFileHandlers() setFileHandler('queue') if connection is None: log.error("Could not connect to broker.") return # TODO CREATE ActionPreority action = ActionPriority(connection, options["task_code"]) queue_worker = Worker(connection, options["task_code"], action) queue_worker.run_worker()
def handle(self, *args, **options): """ Opens connection to broker. Creates ActionWorkflow object. Creates logging handler to send loggings to broker. Sets logging handler to ActionWorkflow object. Performs workflow. Closes connection. """ numeric_level = getattr(logging, options["log_level"].upper(), None) if not isinstance(numeric_level, int): log.error("Invalid log level: %s" % options["log_level"]) numeric_level = 10 broker = BrokerConnection() connection = broker.connect_to_broker() removeFileHandlers() setFileHandler('start') if connection is None: log.error("Could not connect to broker.") return action = ActionWorkflow(connection, options["scenario_id"], options["workflowtemplate_id"]) logging.handlers.AMQPMessageHandler = AMQPMessageHandler broker_handler = logging.handlers.AMQPMessageHandler( action, numeric_level) action.set_broker_logging_handler(broker_handler) action.perform_workflow() if connection.is_open: connection.close()
def handle(self, *args, **options): """ Opens connection to broker. Creates ActionWorkflow object. Creates logging handler to send loggings to broker. Sets logging handler to ActionWorkflow object. Performs workflow. Closes connection. """ numeric_level = getattr(logging, options["log_level"].upper(), None) if not isinstance(numeric_level, int): log.error("Invalid log level: %s" % options["log_level"]) numeric_level = 10 broker = BrokerConnection() connection = broker.connect_to_broker() removeFileHandlers() setFileHandler('start') if connection is None: log.error("Could not connect to broker.") return action = ActionWorkflow( connection, options["scenario_id"], options["workflowtemplate_id"]) logging.handlers.AMQPMessageHandler = AMQPMessageHandler broker_handler = logging.handlers.AMQPMessageHandler(action, numeric_level) action.set_broker_logging_handler(broker_handler) action.perform_workflow() if connection.is_open: connection.close()