def process_event(self, event): """! @brief Run asynchronous processing of an current event. This function will, based on the status of the event: * Ask the Adapter to initialize the Job * Send the Job for execution to the Executor * Send a finish message to the Adapter """ # Checks for real Productstatus events from the message queue if type(event) is eva.event.ProductstatusResourceEvent: # Only process messages with the correct version if event.protocol_version()[0] != 1: self.logger.warning('Event version is %s, but I am only accepting major version 1. Discarding message.', '.'.join(event.protocol_version())) self.statsd.incr('event_version_unsupported') self.remove_event_from_queues(event) return # Discard messages that date from an earlier Resource version if not self.event_matches_object_version(event): self.logger.warning('Resource object version is %d, expecting it to be equal to the Event object version %d. The message is too old, discarding.', event.data.object_version, event.object_version()) self.statsd.incr('resource_object_version_too_old') self.remove_event_from_queues(event) return # Create event job if it has not been created yet if not hasattr(event, 'job'): self.logger.debug('Start processing event: %s', event) self.instantiate_productstatus_data(event) resource = event.data if not self.adapter.validate_resource(resource): self.logger.debug('Adapter did not validate the current event, skipping.') self.statsd.incr('productstatus_rejected_events') self.remove_event_from_queues(event) else: self.logger.debug('Creating a Job object for the current event...') self.statsd.incr('productstatus_accepted_events') event.job = self.adapter.create_job(event.id(), resource) if not event.job: self.logger.debug('No Job object was returned by the adapter; assuming no-op.') self.remove_event_from_queues(event) else: event.job.resource = resource event.job.timer = self.statsd.timer('execution_time') event.job.logger.info('Created Job object for event: %s', event) # Start job if it is not running elif event.job.initialized(): event.job.logger.info('Sending job to executor for asynchronous execution...') event.job.timer.start() self.executor.execute_async(event.job) event.job.logger.info('Job has been sent successfully to the executor.') # Check status of the job elif event.job.started(): if event.job.poll_time_reached(): event.job.logger.debug('Job is running, polling executor for job status...') self.executor.sync(event.job) event.job.logger.debug('Finished polling executor for job status.') # Tell adapter that the job has finished elif event.job.complete() or event.job.failed(): event.job.timer.stop() event.job.logger.info('Finished with total time %.1fs; sending to adapter for finishing.', event.job.timer.total_time_msec() / 1000.0) self.adapter.finish_job(event.job) self.adapter.generate_and_post_resources(event.job) event.job.logger.info('Adapter has finished processing the job.') self.remove_event_from_queues(event) self.logger.debug('Finished processing event: %s', event)
def test_productstatus_event_factory_unrecognized(self): event = eva.event.ProductstatusBaseEvent.factory(unrecognized_serialized_event) self.assertIsInstance(event, eva.event.ProductstatusBaseEvent) self.assertEqual(event.id(), '20000000-0000-0000-0000-000000000002') self.assertEqual(event.timestamp(), eva.coerce_to_utc(datetime.datetime(2016, 1, 5, 12, 0, 0))) self.assertEqual(event.protocol_version(), [1, 5, 0])