Skip to content

Commit

Permalink
Schedule unspecified new schedules on latest available server (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-pie authored Jun 23, 2023
1 parent eef3233 commit 08a4e4a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 19 deletions.
2 changes: 1 addition & 1 deletion cicada/lib/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def insert_schedule_details(db_cur, schedule_details):
if schedule_details["schedule_description"] is not None:
sqlquery = sqlquery + " ,'" + str(schedule_details["schedule_description"]) + "'"
if schedule_details["server_id"] is None:
sqlquery = sqlquery + " ,(SELECT MIN(server_id) FROM servers WHERE is_enabled=1)"
sqlquery = sqlquery + " ,(SELECT MAX(server_id) FROM servers WHERE is_enabled=1)"
else:
sqlquery = sqlquery + " ," + str(schedule_details["server_id"])
if schedule_details["schedule_order"] is not None:
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[build-system]
requires = ["setuptools >= 20.0"]
build-backend = "setuptools.build_meta"

[tool.black]
line-length = 120
22 changes: 11 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name="cicada",
version="0.5.1",
version="0.6.0",
description="Lightweight, agent-based, distributed scheduler",
long_description=long_description,
long_description_content_type="text/markdown",
Expand All @@ -20,19 +20,19 @@
install_requires=[
"psycopg2-binary==2.9.5",
"pyyaml==6.0",
"croniter==1.3.8",
"tabulate==0.9.0",
"slack-sdk==3.19.5",
"backoff==2.2.1",
"croniter==1.3",
"tabulate==0.9",
"slack-sdk==3.19",
"backoff==2.2",
],
extras_require={
"dev": [
"pytest==7.2.0",
"pytest-cov==4.0.0",
"pytest-mock==3.10.0",
"black==22.12.0",
"flake8==6.0.0",
"freezegun==1.2.2",
"pytest==7.3",
"pytest-cov==4.0",
"pytest-mock==3.10",
"black==22.12",
"flake8==6.0",
"freezegun==1.2",
]
},
entry_points={"console_scripts": ["cicada=cicada.cli:main"]},
Expand Down
Empty file added tests/__init__.py
Empty file.
22 changes: 15 additions & 7 deletions tests/test_functional_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,9 @@ def test_exec_schedule():
assert query_result >= 1


def test_exec_schedule_send_alert_if_returncode_not_0_and_config_has_setting_for_all(mocker): # noqa
def test_exec_schedule_send_alert_if_returncode_not_0_and_config_has_setting_for_all(
mocker,
): # noqa
"""test sending alert if returncode is not 0, and config setting is *"""

return_code = choice(list(range(-100, 0)) + list(range(1, 100)))
Expand All @@ -256,7 +258,7 @@ def test_exec_schedule_send_alert_if_returncode_not_0_and_config_has_setting_for
slack:
channel: foo_channel
returncodes_alert: *
"""
""",
)
with TemporaryDirectory() as temp_dir:
for file_content in definitions_contents:
Expand All @@ -268,17 +270,21 @@ def test_exec_schedule_send_alert_if_returncode_not_0_and_config_has_setting_for
mocked_slack.assert_called_once_with("FOO_SCHEDULE_ID", "FOO_LOG_ID", return_code, None, None)


def test_exec_schedule_send_alert_if_returncode_not_0_and_exists_in_config(mocker): # noqa
def test_exec_schedule_send_alert_if_returncode_not_0_and_exists_in_config(
mocker,
): # noqa
"""test sending alert if returncode is not 0, and it is included in the config setting"""
return_code = choice([1, 13, -15])

mocked_slack = mocks_for_alert_test(return_code, mocker=mocker)
with TemporaryDirectory() as temp_dir:
with open(f"{temp_dir}/definitions.yml", "w", encoding="utf-8") as definitions_file:
definitions_file.write("""
definitions_file.write(
"""
slack:
channel: foo_channel
returncodes_alert: [1, 13, -15]""")
returncodes_alert: [1, 13, -15]"""
)

mocker.patch("os.path.join", return_value=f"{temp_dir}/definitions.yml")
exec_schedule.main("FOO_SCHEDULE_ID", "FOO_DB")
Expand All @@ -292,10 +298,12 @@ def test_exec_schedule_not_send_alert_if_returncode_0_but_not_in_config(mocker):
mocked_slack = mocks_for_alert_test(return_code=return_code, mocker=mocker)
with TemporaryDirectory() as temp_dir:
with open(f"{temp_dir}/definitions.yml", "w", encoding="utf-8") as definitions_file:
definitions_file.write("""
definitions_file.write(
"""
slack:
channel: foo_channel
returncodes_alert: [13, -15]""")
returncodes_alert: [13, -15]"""
)

mocker.patch("os.path.join", return_value=f"{temp_dir}/definitions.yml")
exec_schedule.main("FOO_SCHEDULE_ID", "FOO_DB")
Expand Down

0 comments on commit 08a4e4a

Please sign in to comment.