'Called when a crawled task is arrived'

def on_old_request(self, task, old_task):

    now = time.time()
    _schedule = task.get('schedule', self.default_schedule)
    old_schedule = old_task.get('schedule', {})
    if (_schedule.get('force_update') and self.projects[task['project']].task_queue.is_processing(task['taskid'])):
        logger.info('postpone    modify    task    %(project)s:%(taskid)s    %(url)s', task)
        self._postpone_request.append(task)
        return
    restart = False
    schedule_age = _schedule.get('age', self.default_schedule['age'])
    if (_schedule.get('itag') and (_schedule['itag'] != old_schedule.get('itag'))):
        restart = True
    elif ((schedule_age >= 0) and ((schedule_age + (old_task.get('lastcrawltime', 0) or 0)) < now)):
        restart = True
    elif _schedule.get('force_update'):
        restart = True
    if (not restart):
        logger.debug('ignore    newtask    %(project)s:%(taskid)s    %(url)s', task)
        return
    if _schedule.get('cancel'):
        logger.info('cancel    task    %(project)s:%(taskid)s    %(url)s', task)
        task['status'] = self.taskdb.BAD
        self.update_task(task)
        self.projects[task['project']].task_queue.delete(task['taskid'])
        return task
    task['status'] = self.taskdb.ACTIVE
    self.update_task(task)
    self.put_task(task)
    project = task['project']
    if (old_task['status'] != self.taskdb.ACTIVE):
        self._cnt['5m'].event((project, 'pending'), (+ 1))
        self._cnt['1h'].event((project, 'pending'), (+ 1))
        self._cnt['1d'].event((project, 'pending'), (+ 1))
    if (old_task['status'] == self.taskdb.SUCCESS):
        self._cnt['all'].event((project, 'success'), (-1)).event((project, 'pending'), (+ 1))
    elif (old_task['status'] == self.taskdb.FAILED):
        self._cnt['all'].event((project, 'failed'), (-1)).event((project, 'pending'), (+ 1))
    logger.info('restart    task    %(project)s:%(taskid)s    %(url)s', task)
    return task
