def save(self, *args, **kwargs): from task.utils.scheduler import add_job # 新建 if not self.pk: super(RSSTask, self).save(*args, **kwargs) id = self.pk add_job(id, self.frequency, 'rss') task_status = TaskStatus(task_name=self.name, task_id=id, task_type='rss') task_status.save() else: super(RSSTask, self).save(*args, **kwargs) id = self.pk task_status = TaskStatus.objects.get(task_id=id, task_type='rss') task_status.task_name = self.name task_status.last_status = '更新任务成功' task_status.last_run = datetime.now() task_status.task_status = 0 task_status.save() add_job(id, self.frequency, 'rss') logger.info('task_RSS{}更新'.format(id))
def save(self, *args, **kwargs): from task.utils.scheduler import add_job, remove_job super(TaskStatus, self).save(*args, **kwargs) task_id = self.task_id if self.task_status == 0: if self.last_status != '更新任务成功': if self.task_type == 'html': task = Task.objects.get(id=task_id) add_job(task_id, task.frequency) elif self.task_type == 'rss': rss_task = RSSTask.objects.get(id=task_id) add_job(task_id, rss_task.frequency, 'rss') else: if self.task_type == 'html': remove_job(task_id) elif self.task_type == 'rss': remove_job(task_id, 'rss')