mirror of
https://github.com/getredash/redash.git
synced 2026-03-22 10:00:17 -04:00
* enforce hard limits on non-responsive work horses by workers
* move differences from Worker to helper methods to help make the specialization clearer
* move HardLimitingWorker to redash/tasks
* move schedule.py to /tasks
* explain the motivation for HardLimitingWorker
* pleasing CodeClimate
* pleasing CodeClimate
* port query execution to RQ
* get rid of argsrepr
* avoid star imports
* allow queries to be cancelled in RQ
* return QueryExecutionErrors as job results
* fix TestTaskEnqueue and QueryExecutorTests
* remove Celery monitoring
* get rid of QueryTask and use RQ jobs directly (with a job serializer)
* Revert "remove Celery monitoring"
This reverts commit 37a74ea403.
* reduce occurences of the word 'task'
* use Worker, Queue and Job instead of spreading names that share behavior details
* remove locks for failed jobs as well
* did I not commit that colon? oh my
* push the redis connection to RQ's stack on every request to avoid verbose connection setting
* use a connection context for tests
* black it up
* run RQ on all queues when running in Cypress
65 lines
1.9 KiB
Python
65 lines
1.9 KiB
Python
from unittest import TestCase
|
|
from mock import patch, ANY
|
|
|
|
from redash.tasks.schedule import rq_scheduler, schedule_periodic_jobs
|
|
|
|
|
|
class TestSchedule(TestCase):
|
|
def setUp(self):
|
|
for job in rq_scheduler.get_jobs():
|
|
rq_scheduler.cancel(job)
|
|
job.delete()
|
|
|
|
def test_schedules_a_new_job(self):
|
|
def foo():
|
|
pass
|
|
|
|
schedule_periodic_jobs([{"func": foo, "interval": 60}])
|
|
|
|
jobs = [job for job in rq_scheduler.get_jobs()]
|
|
|
|
self.assertEqual(len(jobs), 1)
|
|
self.assertTrue(jobs[0].func_name.endswith("foo"))
|
|
self.assertEqual(jobs[0].meta["interval"], 60)
|
|
|
|
def test_doesnt_reschedule_an_existing_job(self):
|
|
def foo():
|
|
pass
|
|
|
|
schedule_periodic_jobs([{"func": foo, "interval": 60}])
|
|
with patch("redash.tasks.rq_scheduler.schedule") as schedule:
|
|
schedule_periodic_jobs([{"func": foo, "interval": 60}])
|
|
schedule.assert_not_called()
|
|
|
|
def test_reschedules_a_modified_job(self):
|
|
def foo():
|
|
pass
|
|
|
|
schedule_periodic_jobs([{"func": foo, "interval": 60}])
|
|
schedule_periodic_jobs([{"func": foo, "interval": 120}])
|
|
|
|
jobs = [job for job in rq_scheduler.get_jobs()]
|
|
|
|
self.assertEqual(len(jobs), 1)
|
|
self.assertTrue(jobs[0].func_name.endswith("foo"))
|
|
self.assertEqual(jobs[0].meta["interval"], 120)
|
|
|
|
def test_removes_jobs_that_are_no_longer_defined(self):
|
|
def foo():
|
|
pass
|
|
|
|
def bar():
|
|
pass
|
|
|
|
schedule_periodic_jobs(
|
|
[{"func": foo, "interval": 60}, {"func": bar, "interval": 90}]
|
|
)
|
|
schedule_periodic_jobs([{"func": foo, "interval": 60}])
|
|
|
|
jobs = [job for job in rq_scheduler.get_jobs()]
|
|
|
|
self.assertEqual(len(jobs), 1)
|
|
self.assertTrue(jobs[0].func_name.endswith("foo"))
|
|
self.assertEqual(jobs[0].meta["interval"], 60)
|
|
|