Commit daca3d40 authored by Vasyl Bodnaruk's avatar Vasyl Bodnaruk

added functional for running by specific time

parent 8427e299
......@@ -158,5 +158,5 @@ CELERY_BROKER_URL = 'amqp://guest:guest@localhost//'
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_BACKEND = 'rpc'
# CELERY_RESULT_BACKEND = 'rpc'
CELERY_RESULT_PERSISTENT = True
from __future__ import absolute_import, unicode_literals
from celery import shared_task
from .service import Service
from .models import Job
@shared_task
......@@ -10,8 +11,24 @@ def add(x, y):
@shared_task
def run_job(job):
def run_job(job_id):
api = Service()
print('RUN spider')
api.run_job(job)
job = Job.objects.get(pk=job_id)
# run job nonstop
if job.status == Job.FINISHED and job.interval == Job.NON:
print('NONSTOP')
api.run_job(job_id)
# run job with some interval
elif job.interval and job.interval != Job.NON:
print('INTERVAL')
api.run_job(job_id)
# run only one time
elif job.status == Job.PENDING and not job.interval:
print('ONE time')
api.run_job(job_id)
job.schedule_job.delete()
return 'spider was running'
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