def perform_job(self, job):
        """Performs the actual work of a job.  Will/should only be called
        inside the work horse's process.
        """
        self.procline('Processing %s from %s since %s' % (
            job.func_name,
            job.origin, time.time()))

               # do it this way to avoid the extra sql call through job
        for q in self.queues:
            if q.name == job.queue_id:
                break
        try:
            with death_penalty_after(job.timeout or PQ_DEFAULT_JOB_TIMEOUT):
                rv = job.perform()

            # Pickle the result in the same try-except block since we need to
            # use the same exc handling when pickling fails
            job.result = rv
            job.status = Job.FINISHED
            job.ended_at = now()
            job.result_ttl = job.get_ttl(self.default_result_ttl)
            if job.result_ttl > 0:
                ttl = timedelta(seconds=job.result_ttl)
                job.expired_at = job.ended_at + ttl
            if job.result_ttl != 0:
                job.save()
            else:
                job.delete()

        except:
            job.status = Job.FAILED
            job.save()
            if job.flow_id:
                Flow.handle_failed(job, q)
            self.handle_exception(job, *sys.exc_info())
            return False

        if q.serial:
            q.release_lock()

        if rv is None:
            self.log.info('Job OK')
        else:
            # the six u doesnt seem compatible
            # with converting an integer
            try:
                msg = unicode(rv)
            except __HOLE__:
                msg = str(rv)
            self.log.info('Job OK, result = %s' % (yellow(msg),))
        if job.flow_id:
            Flow.handle_result(job, q)
        if job.result_ttl == 0:
            self.log.info('Result discarded immediately.')
        elif job.result_ttl > 0:
            self.log.info('Result is kept for %d seconds.' % job.result_ttl)
        else:
            self.log.warning('Result will never expire, clean up result key manually.')

        return True
dataset/ETHPy150Open bretth/django-pq/pq/worker.py/Worker.perform_job