def celery_status(self): if self.status == 2: return 'SUCCESS' if not self.cid: return 'NO SUBMIT' status = AsyncResult(self.cid).status if status != 'SUCCESS' and self.started_at and utc_now().timestamp( ) - self.started_at.timestamp() > 300: return 'ABORT' return status
def notification_service(self): from task.models import Notice connection = mail.get_connection() connection.open() cid = str(self.request.id) notices = Notice.objects.filter(status=0, cid='') notices.update(cid=cid) for notice in Notice.objects.filter(cid=cid): notice.send() notice.started_at = utc_now() notice.status = 1 notice.save() for notice in Notice.objects.filter(status=1): if notice.celery_status == 'ABORT': notice.cid = cid notice.send() notice.finished_at = utc_now() notice.status = 2 notice.save() connection.close()
def run(self): self.task.status = self.task.StatusChoices.RUNNING self.task.started_at = utc_now() self.task.save() self.task.run_notices() self.task.rc, self.task.msg = subprocess.getstatusoutput(self.task.cmd) if 'Invalid sequence file. Please make sure file is in FASTA format' in self.task.msg: self.task.rc = 1 self.task.save() if self.task.rc: self.task.fail() else: self.task.success()
def success(self): self.status = self.StatusChoices.SUCCESS self.finished_at = utc_now() self.save() self.success_notices()
def fail(self): self.status = self.StatusChoices.FAIL self.finished_at = utc_now() self.save() self.fail_notices()