Example #1
0
def start_fetching():
    scheduler = Scheduler(connection=get_connection())
    from app.tasks import fetch_data
    scheduler.schedule(scheduled_time=datetime.utcnow(),
                       func=fetch_data,
                       interval=int(60),
                       repeat=None)
Example #2
0
def job_result(id):
    """ 通过任务id来返回结果 """
    conn = get_connection()
    result = conn.hget(id, 'result')
    if result:
        return rq_loads(result)
    return "Working ..."
Example #3
0
def get_current_job():
    rq_job = rq.get_current_job(connection=get_connection())
    return Job.query.get(rq_job.id)
Example #4
0
def get_current_job():
    rq_job = rq.get_current_job(connection=get_connection())
    return Job.query.get(rq_job.id)
Example #5
0
 def test_connection_from_url(self):
     connection = get_connection('high')
     connection_kwargs = connection.connection_pool.connection_kwargs
     self.assertEqual(connection_kwargs.get('host'), 'localhost')
     self.assertEqual(connection_kwargs.get('port'), 6379)
     self.assertEqual(connection_kwargs.get('db'), 3)
Example #6
0
 def test_get_connection_default(self):
     connection = get_connection()
     connection_kwargs = connection.connection_pool.connection_kwargs
     self.assertEqual(connection_kwargs.get('host'), 'localhost')
     self.assertEqual(connection_kwargs.get('port'), 6379)
Example #7
0
def get_job_id():
    rq_job = rq.get_current_job(connection=get_connection())
    return rq_job.id
Example #8
0
 def test_connection_from_url(self):
     connection = get_connection('high')
     connection_kwargs = connection.connection_pool.connection_kwargs
     self.assertEqual(connection_kwargs.get('host'), 'localhost')
     self.assertEqual(connection_kwargs.get('port'), 6379)
     self.assertEqual(connection_kwargs.get('db'), 3)
Example #9
0
 def test_get_connection_default(self):
     connection = get_connection()
     connection_kwargs = connection.connection_pool.connection_kwargs
     self.assertEqual(connection_kwargs.get('host'), 'localhost')
     self.assertEqual(connection_kwargs.get('port'), 6379)
Example #10
0
def run_scheduler():
    """rq-scheduler for periodic tasks"""
    if app.debug:
        setup_loghandlers('DEBUG')
    scheduler = Scheduler(connection=get_connection(), interval=30)
    scheduler.run()
Example #11
0
def run_worker():
    """Initializes a rq task queue."""
    listen = ['default']
    with Connection(get_connection()):
        worker = Worker(map(Queue, listen))
        worker.work(with_scheduler=False)
Example #12
0
def stop_fetching():
    scheduler = Scheduler(connection=get_connection())
    for j in scheduler.get_jobs():
        scheduler.cancel(j)
Example #13
0
def get_job_id():
    rq_job = rq.get_current_job(connection=get_connection())
    return rq_job.id