Skip to content

Commit 6caf2bb

Browse files
authored
Merge pull request #55 from man-group/feature/scheduling
fix: use correct default scheduler mongo database
2 parents 8df0066 + a800f5c commit 6caf2bb

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

notebooker/web/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def setup_scheduler(flask_app, web_config):
9999
serializer = get_serializer_from_cls(web_config.SERIALIZER_CLS, **web_config.SERIALIZER_CONFIG)
100100
if isinstance(serializer, MongoResultSerializer):
101101
client = serializer.get_mongo_connection()
102-
database = web_config.SCHEDULER_MONGO_DATABASE or serializer.mongo_host
102+
database = web_config.SCHEDULER_MONGO_DATABASE or serializer.database_name
103103
collection = web_config.SCHEDULER_MONGO_COLLECTION or f"{serializer.result_collection_name}_scheduler"
104104
jobstores = {"mongo": MongoDBJobStore(database=database, collection=collection, client=client)}
105105
else:

tests/conftest.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ def webapp_config(mongo_host, test_db_name, test_lib_name, template_dir, cache_d
8181
},
8282
PY_TEMPLATE_BASE_DIR=workspace.workspace,
8383
PY_TEMPLATE_SUBDIR="templates",
84-
SCHEDULER_MONGO_COLLECTION=test_lib_name,
85-
SCHEDULER_MONGO_DATABASE=test_db_name,
8684
)
8785

8886

tests/integration/web/test_app.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import mock
2+
3+
from notebooker.web.app import setup_scheduler
4+
5+
6+
def test_setup_scheduler_disabled(flask_app, webapp_config):
7+
webapp_config.DISABLE_SCHEDULER = True
8+
app = setup_scheduler(flask_app, webapp_config)
9+
assert app.apscheduler is None
10+
11+
12+
def test_setup_scheduler(flask_app, webapp_config, test_db_name, test_lib_name):
13+
webapp_config.DISABLE_SCHEDULER = False
14+
scheduler_coll = f"{test_lib_name}_scheduler"
15+
with mock.patch("notebooker.web.app.BackgroundScheduler") as sched:
16+
with mock.patch("notebooker.web.app.MongoDBJobStore") as jobstore:
17+
app = setup_scheduler(flask_app, webapp_config)
18+
assert app.apscheduler is not None
19+
jobstore.assert_called_with(database=test_db_name, collection=scheduler_coll, client=mock.ANY)

tests/integration/web/test_scheduling.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,12 @@ def test_delete_scheduled_jobs(flask_app, setup_workspace):
110110

111111
def test_scheduler_runs_notebooks(flask_app, setup_workspace):
112112
with flask_app.test_client() as client:
113+
113114
def fake_post(url, params):
114115
path = url.replace("http://", "").split("/", 1)[1]
115116
client.post(f"/{path}?{params}")
116117
return mock.MagicMock()
118+
117119
with mock.patch("notebooker.web.scheduler.requests.post", side_effect=fake_post):
118120
rv = client.get("/core/get_all_available_results?limit=50")
119121
assert len(json.loads(rv.data)) == 0

0 commit comments

Comments
 (0)