Commit bffd2c64 authored by Vasyl Bodnaruk's avatar Vasyl Bodnaruk

Add functional for cancel job

parent 337bba66
from datetime import datetime
from scrapyd_api import ScrapydAPI
from .models import Spider, Job
from .models import Job
class Service:
......@@ -20,9 +20,15 @@ class Service:
def run_job(self, job):
job = Job.objects.get(pk=job)
print(job.spider.sp_name)
uuid = self.api.schedule('exa', job.spider.sp_name)
job.job_uuid = uuid
job.start_time = datetime.now()
job.status = 'RUN'
job.save()
def cancel_job(self, job):
job = Job.objects.get(pk=job)
self.api.cancel('exa', job.job_uuid)
job.end_time = datetime.now()
job.status = 'FIN'
job.save()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment