Example #1
0
    def publish_experiment_job_log(self,
                                   log_lines,
                                   experiment_uuid,
                                   experiment_name,
                                   job_uuid,
                                   send_task=True):
        self._logger.debug("Publishing log event for task: %s, %s", job_uuid,
                           experiment_name)

        if send_task:
            celery_app.send_task(LogsCeleryTasks.LOGS_HANDLE_EXPERIMENT_JOB,
                                 kwargs={
                                     'experiment_name': experiment_name,
                                     'experiment_uuid': experiment_uuid,
                                     'log_lines': log_lines,
                                     'temp': True
                                 })
        try:
            should_stream = (
                RedisToStream.is_monitored_job_logs(job_uuid)
                or RedisToStream.is_monitored_experiment_logs(experiment_uuid))
        except RedisError:
            should_stream = False
        if should_stream:
            self._logger.info(
                "Streaming new log event for experiment: %s job: %s",
                experiment_uuid, job_uuid)

            with celery_app.producer_or_acquire(None) as producer:
                try:
                    producer.publish(
                        {
                            'experiment_uuid': experiment_uuid,
                            'job_uuid': job_uuid,
                            'log_lines': log_lines,
                        },
                        retry=True,
                        routing_key='{}.{}.{}'.format(
                            RoutingKeys.STREAM_LOGS_SIDECARS_EXPERIMENTS,
                            experiment_uuid, job_uuid),
                        exchange=settings.INTERNAL_EXCHANGE,
                    )
                except (TimeoutError, AMQPError):
                    pass
Example #2
0
    def _stream_job_log(self, job_uuid, log_lines, routing_key):
        try:
            should_stream = RedisToStream.is_monitored_job_logs(job_uuid)
        except RedisError:
            should_stream = False
        if should_stream:
            self._logger.info("Streaming new log event for job: %s", job_uuid)

            with celery_app.producer_or_acquire(None) as producer:
                try:
                    producer.publish(
                        {
                            'job_uuid': job_uuid,
                            'log_lines': log_lines,
                        },
                        retry=True,
                        routing_key='{}.{}'.format(routing_key, job_uuid),
                        exchange=settings.INTERNAL_EXCHANGE,
                    )
                except (TimeoutError, AMQPError):
                    pass