Example #1
0
    def publish(self, task, *args, **kwargs):
        job = Job(task=task, args=args, kwargs=kwargs, serializer=self.serializer, backend=self.result)
        job.save()

        self._publish(job, *args, **kwargs)

        self.logger.info("%r published" % job)

        signals.job_published.send(job)

        return job
Example #2
0
    def handle(self, message):
        job = Job.fetch(key=self._get_job_id(message), backend=self.result, serializer=self.serializer)

        signals.job_received.send(job)

        self.logger.info("%r received" % job)

        ts = time.time()

        result = None

        try:
            with self.death_penalty_class(job.timeout or defaults.TIMEOUT):
                result = job()

            job.result = result
        except Exception:
            exc_string = self.handle_exception(job, *sys.exc_info())

            job.error = exc_string

            laps = time.time() - ts

            job.exec_time = laps
            job.set_status_failed(commit=False)

            self.logger.warning("%r failed in %2.3f seconds" % (job, laps))

            result = False

            if job.can_retry():
                job.child = self.retry(job, message)

                signals.job_retried.send(job)

                result = True

            job.save()

            signals.job_failed.send(job)
            signals.job_finished.send(job)

            return result

        laps = time.time() - ts

        job.set_status_succeeded(commit=False)
        job.exec_time = laps
        job.save()

        signals.job_succeeded.send(job)
        signals.job_finished.send(job)

        self.logger.info("%r succeeded in %2.3f seconds" % (job, laps))

        return True
Example #3
0
    def test_fetch_job(self):
        job = self.message.delay('test')

        retrieved_job = Job.fetch(job.key, backend=self.result, serializer=self.serializer)

        assert job == retrieved_job