<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def job_error(self, job, queue, exception, trace=None):
 """ Called when an exception was raised during the execute call for a job. """

        to_be_requeued = not job.must_be_cancelled_on_error and self.requeue_times and self.requeue_times >= int(job.tries.hget() or 0)

        if not to_be_requeued:
            job.queued.delete()

        job.hmset(end=str(datetime.utcnow()), status=STATUSES.ERROR)
        queue.errors.rpush(job.ident)

        if self.save_errors:
            additional_fields = self.additional_error_fields(job, queue, exception)
            self.error_model.add_error(queue_name=queue._cached_name,
                                       job=job,
                                       error=exception,
                                       trace=trace,
                                       **additional_fields)

        self.log(self.job_error_message(job, queue, to_be_requeued, exception, trace), level='error')

        if hasattr(job, 'on_error'):
            job.on_error(queue, exception, trace)

        # requeue the job if needed
        if to_be_requeued:
            priority = queue.priority.hget()

            if self.requeue_priority_delta:
                priority = int(priority) + self.requeue_priority_delta

            self.requeue_job(job, queue, priority, delayed_for=self.requeue_delay_delta)