Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breaking change: Drop support for Dkron 3.1.x #49

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions dkron/management/commands/run_dkron.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,18 @@ def handle(self, *_, **options):
if settings.DKRON_WORKDIR:
os.chdir(settings.DKRON_WORKDIR)
if settings.DKRON_PRE_WEBHOOK_URL and settings.DKRON_TOKEN and settings.DKRON_SENTRY_CRON_URL:
flag_name = '--pre-webhook-url' if utils.dkron_binary_version() < (3, 2, 0) else '--pre-webhook-endpoint'
args.extend(
[
flag_name,
'--pre-webhook-endpoint',
settings.DKRON_PRE_WEBHOOK_URL,
'--pre-webhook-payload',
f'{settings.DKRON_TOKEN}\n{{{{ .JobName }}}}',
]
)
if settings.DKRON_WEBHOOK_URL and settings.DKRON_TOKEN:
flag_name = '--webhook-url' if utils.dkron_binary_version() < (3, 2, 0) else '--webhook-endpoint'
args.extend(
[
flag_name,
'--webhook-endpoint',
settings.DKRON_WEBHOOK_URL,
'--webhook-payload',
f'{settings.DKRON_TOKEN}\n{{{{ .JobName }}}}\n{{{{ .Success }}}}',
Expand Down
13 changes: 2 additions & 11 deletions dkron/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

from django.conf import settings
from django.core.management import call_command
from django.utils import timezone

from dkron import models

Expand Down Expand Up @@ -299,26 +298,18 @@ def __run_async_dkron(_command, *args, **kwargs) -> tuple[str, str]:

name = f'tmp_{_command}_{time.time():.0f}'

if dkron_binary_version() >= (3, 2, 2):
# runoncreate was turned into asynchronous in https://github.com/distribworks/dkron/pull/1269
schedule = '@manually'
params = {'runoncreate': 'true'}
else:
schedule = f'@at {(timezone.now() + timezone.timedelta(seconds=5)).isoformat()}'
params = {}

r = _post(
'jobs',
json={
'name': add_namespace(name),
'schedule': schedule,
'schedule': '@manually',
'executor': 'shell',
'tags': {'label': f'{settings.DKRON_JOB_LABEL}:1'} if settings.DKRON_JOB_LABEL else {},
'metadata': {'temp': 'true'},
'disabled': False,
'executor_config': {'command': final_command},
},
params=params,
params={'runoncreate': 'true'},
)

if r.status_code != 201:
Expand Down
44 changes: 10 additions & 34 deletions testapp/tests/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,19 +460,7 @@ def test_run_async(self, mp, tp, job_prefix=''):
# https://docs.python.org/3/library/unittest.mock.html#raising-exceptions-on-attribute-access
type(mpp).status_code = mock.PropertyMock(side_effect=[201, 200])
with mock.patch('django.utils.timezone.now', return_value=timezone.make_aware(timezone.datetime(2023, 2, 7))):
with override_settings(DKRON_VERSION='3.2.2'):
x = utils.run_async('somecommand', 'arg1', kwarg='value', enable=True)
mp.assert_has_calls([expected_mock_call])
self.assertEqual(x, expected_return)

mp.reset_mock()

expected_mock_call.kwargs['json']['schedule'] = '@at 2023-02-07T00:00:05+00:00'
expected_mock_call.kwargs['params'] = {}
type(mpp).status_code = mock.PropertyMock(side_effect=[201, 200])
utils.dkron_binary_version.cache_clear()
with override_settings(DKRON_VERSION='3.1.10'):
x = utils.run_async('somecommand', 'arg1', kwarg='value', enable=True)
x = utils.run_async('somecommand', 'arg1', kwarg='value', enable=True)
mp.assert_has_calls([expected_mock_call])
self.assertEqual(x, expected_return)

Expand Down Expand Up @@ -597,27 +585,15 @@ def test_run_dkron_webhook(self, exec_mock):
f.write(b'1')

with mock.patch('tempfile.mkdtemp', return_value=tmp):
with override_settings(DKRON_VERSION='3.1.10'):
management.call_command('run_dkron', stdout=out, stderr=err)
self.assertEqual(exec_mock.call_count, 1)
exec_args = exec_mock.call_args_list[0][0][1]
self.assertIn('--webhook-url', exec_args)
opt_i = exec_args.index('--webhook-url')
self.assertEqual(
exec_args[opt_i : opt_i + 3], ['--webhook-url', 'https://whatever', '--webhook-payload']
)

exec_mock.reset_mock()
with override_settings(DKRON_VERSION='3.2.1'):
utils.dkron_binary_version.cache_clear()
management.call_command('run_dkron', stdout=out, stderr=err)
self.assertEqual(exec_mock.call_count, 1)
exec_args = exec_mock.call_args_list[0][0][1]
self.assertIn('--webhook-endpoint', exec_args)
opt_i = exec_args.index('--webhook-endpoint')
self.assertEqual(
exec_args[opt_i : opt_i + 3], ['--webhook-endpoint', 'https://whatever', '--webhook-payload']
)
utils.dkron_binary_version.cache_clear()
management.call_command('run_dkron', stdout=out, stderr=err)
self.assertEqual(exec_mock.call_count, 1)
exec_args = exec_mock.call_args_list[0][0][1]
self.assertIn('--webhook-endpoint', exec_args)
opt_i = exec_args.index('--webhook-endpoint')
self.assertEqual(
exec_args[opt_i : opt_i + 3], ['--webhook-endpoint', 'https://whatever', '--webhook-payload']
)

@mock.patch('requests.request')
def test_proxy_auth(self, mp1):
Expand Down
12 changes: 6 additions & 6 deletions testapp/tests/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Test(TestCase):
@mock.patch('platform.machine')
@mock.patch('platform.system')
@mock.patch('requests.get')
@override_settings(DKRON_BIN_DIR=None, DKRON_VERSION='3.1.10')
@override_settings(DKRON_BIN_DIR=None, DKRON_VERSION='3.2.7')
def test_run_dkron_download(self, req_mock, sys_mock, mach_mock):
from dkron.management.commands import run_dkron
from io import BytesIO
Expand All @@ -38,23 +38,23 @@ def _check(system, machine, url):
_check(
'darwin',
'x86_64',
'https://github.com/distribworks/dkron/releases/download/v3.1.10/dkron_3.1.10_darwin_amd64.tar.gz',
'https://github.com/distribworks/dkron/releases/download/v3.2.7/dkron_3.2.7_darwin_amd64.tar.gz',
)
_check(
'windows',
'AMD64',
'https://github.com/distribworks/dkron/releases/download/v3.1.10/dkron_3.1.10_windows_amd64.tar.gz',
'https://github.com/distribworks/dkron/releases/download/v3.2.7/dkron_3.2.7_windows_amd64.tar.gz',
)
_check(
'Linux',
'aarch64',
'https://github.com/distribworks/dkron/releases/download/v3.1.10/dkron_3.1.10_linux_arm64.tar.gz',
'https://github.com/distribworks/dkron/releases/download/v3.2.7/dkron_3.2.7_linux_arm64.tar.gz',
)

def test_utils_dkron_version_tuple(self):
utils.dkron_binary_version.cache_clear()
with override_settings(DKRON_VERSION='3.1.1'):
self.assertEqual(utils.dkron_binary_version(), (3, 1, 1))
with override_settings(DKRON_VERSION='3.2.7'):
self.assertEqual(utils.dkron_binary_version(), (3, 2, 7))

utils.dkron_binary_version.cache_clear()
with override_settings(DKRON_VERSION='4.1.1-fork1'):
Expand Down
Loading