Skip to content

Commit

Permalink
Merge pull request zmap#51 from rafaelreuber/issue_37
Browse files Browse the repository at this point in the history
[Fix zmap#37]: Enabled tasks do not run when there is another schedule en…
  • Loading branch information
zakird authored May 11, 2020
2 parents d5bad02 + 97ad656 commit 49d5205
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion celerybeatmongo/schedulers.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def requires_update(self):
def get_from_database(self):
self.sync()
d = {}
for doc in self.Model.objects():
for doc in self.Model.objects.filter(enabled=True):
d[doc.name] = self.Entry(doc)
return d

Expand Down
29 changes: 29 additions & 0 deletions tests/test_scheduler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

import unittest
from mongoengine import disconnect
from celerybeatmongo.schedulers import MongoScheduler
from celery import Celery


class MongoSchedulerTest(unittest.TestCase):

def setUp(self):
conf = {
"mongodb_scheduler_url": "mongomock://localhost"
}
self.app = Celery(**conf)
self.app.conf.update(**conf)
self.scheduler = MongoScheduler(app=self.app)

def tearDown(self):
disconnect()

def test_get_from_database(self):
from celerybeatmongo.models import PeriodicTask
PeriodicTask.objects.create(name="a1", task="foo", enabled=True, interval=PeriodicTask.Interval(every=1, period="days"))
PeriodicTask.objects.create(name="b1", task="foo", enabled=True, interval=PeriodicTask.Interval(every=2, period="days"))
PeriodicTask.objects.create(name="c2", task="foo", enabled=False, interval=PeriodicTask.Interval(every=3, period="days"))

scheduler = MongoScheduler(app=self.app)
self.assertEqual(2, len(scheduler.get_from_database())
, "get_from_database should return just enabled tasks")

0 comments on commit 49d5205

Please sign in to comment.