From 10c529022d80c245b97c4659533bfb549eb0c634 Mon Sep 17 00:00:00 2001 From: Jennifer Richards Date: Mon, 13 May 2024 22:24:55 -0300 Subject: [PATCH 1/4] feat: expire_last_calls_task --- ietf/doc/tasks.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ietf/doc/tasks.py b/ietf/doc/tasks.py index a2e83e9e26..117a84bb6f 100644 --- a/ietf/doc/tasks.py +++ b/ietf/doc/tasks.py @@ -20,6 +20,7 @@ get_soon_to_expire_drafts, send_expire_warning_for_draft, ) +from .lastcall import get_expired_last_calls, expire_last_call from .models import Document @@ -54,3 +55,14 @@ def expire_ids_task(): def notify_expirations_task(notify_days=14): for doc in get_soon_to_expire_drafts(notify_days): send_expire_warning_for_draft(doc) + + +@shared_task +def expire_last_calls_task(): + for doc in get_expired_last_calls(): + try: + expire_last_call(doc) + except Exception: + log.log(f"ERROR: Failed to expire last call for {doc.file_tag()} (id={doc.pk})") + else: + log.log(f"Expired last call for {doc.file_tag()} (id={doc.pk})") From 42aa0b6bf4a0041dd2bf261c5a17c8be553add18 Mon Sep 17 00:00:00 2001 From: Jennifer Richards Date: Mon, 13 May 2024 22:56:18 -0300 Subject: [PATCH 2/4] feat: create periodic task for last calls --- ietf/utils/management/commands/periodic_tasks.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ietf/utils/management/commands/periodic_tasks.py b/ietf/utils/management/commands/periodic_tasks.py index e359382839..72d68ba9ad 100644 --- a/ietf/utils/management/commands/periodic_tasks.py +++ b/ietf/utils/management/commands/periodic_tasks.py @@ -141,6 +141,16 @@ def create_default_tasks(self): ), ) + PeriodicTask.objects.get_or_create( + name="Expire Last Calls", + task="ietf.doc.tasks.expire_last_calls_task", + defaults=dict( + enabled=False, + crontab=self.crontabs["daily"], + description="Move docs whose last call has expired to their next states", + ), + ) + PeriodicTask.objects.get_or_create( name="Sync with IANA changes", task="ietf.sync.tasks.iana_changes_update_task", From 6db4b3c7a833d32c12cc4cbfb50b198502bcd050 Mon Sep 17 00:00:00 2001 From: Jennifer Richards Date: Mon, 13 May 2024 23:04:47 -0300 Subject: [PATCH 3/4] test: test new task --- ietf/doc/tests_tasks.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/ietf/doc/tests_tasks.py b/ietf/doc/tests_tasks.py index 931ed438dc..db40bd0686 100644 --- a/ietf/doc/tests_tasks.py +++ b/ietf/doc/tests_tasks.py @@ -6,7 +6,7 @@ from .factories import DocumentFactory from .models import Document -from .tasks import expire_ids_task, notify_expirations_task +from .tasks import expire_ids_task, expire_last_calls_task, notify_expirations_task class TaskTests(TestCase): @@ -61,3 +61,26 @@ def test_notify_expirations_task(self, get_drafts_mock, send_warning_mock): notify_expirations_task() self.assertEqual(send_warning_mock.call_count, 1) self.assertEqual(send_warning_mock.call_args[0], ("sentinel",)) + + @mock.patch("ietf.doc.tasks.expire_last_call") + @mock.patch("ietf.doc.tasks.get_expired_last_calls") + def test_expire_last_calls_task(self, mock_get_expired, mock_expire): + docs = DocumentFactory.create_batch(3) + mock_get_expired.return_value = docs + expire_last_calls_task() + self.assertTrue(mock_get_expired.called) + self.assertEqual(mock_expire.call_count, 3) + self.assertEqual(mock_expire.call_args_list[0], mock.call(docs[0])) + self.assertEqual(mock_expire.call_args_list[1], mock.call(docs[1])) + self.assertEqual(mock_expire.call_args_list[2], mock.call(docs[2])) + + # Check that it runs even if exceptions occur + mock_get_expired.reset_mock() + mock_expire.reset_mock() + mock_expire.side_effect = ValueError + expire_last_calls_task() + self.assertTrue(mock_get_expired.called) + self.assertEqual(mock_expire.call_count, 3) + self.assertEqual(mock_expire.call_args_list[0], mock.call(docs[0])) + self.assertEqual(mock_expire.call_args_list[1], mock.call(docs[1])) + self.assertEqual(mock_expire.call_args_list[2], mock.call(docs[2])) From 458da6ade607bb2fd6e3f477237befeff16b5ee8 Mon Sep 17 00:00:00 2001 From: Jennifer Richards Date: Mon, 13 May 2024 23:20:36 -0300 Subject: [PATCH 4/4] chore: remove expire-last-calls script --- bin/daily | 4 ---- ietf/bin/expire-last-calls | 34 ---------------------------------- 2 files changed, 38 deletions(-) delete mode 100755 ietf/bin/expire-last-calls diff --git a/bin/daily b/bin/daily index 8211e1e237..fbde478792 100755 --- a/bin/daily +++ b/bin/daily @@ -43,9 +43,5 @@ $DTDIR/ietf/manage.py populate_yang_model_dirs -v0 # Re-run yang checks on active documents $DTDIR/ietf/manage.py run_yang_model_checks -v0 -# Expire last calls -# Enable when removed from /a/www/ietf-datatracker/scripts/Cron-runner: -$DTDIR/ietf/bin/expire-last-calls - # Purge older PersonApiKeyEvents $DTDIR/ietf/manage.py purge_old_personal_api_key_events 14 diff --git a/ietf/bin/expire-last-calls b/ietf/bin/expire-last-calls deleted file mode 100755 index 83b565e192..0000000000 --- a/ietf/bin/expire-last-calls +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env python - -# This script requires that the proper virtual python environment has been -# invoked before start - -import os -import sys -import syslog - -# boilerplate -basedir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")) -sys.path = [ basedir ] + sys.path -os.environ["DJANGO_SETTINGS_MODULE"] = "ietf.settings" - -virtualenv_activation = os.path.join(basedir, "env", "bin", "activate_this.py") -if os.path.exists(virtualenv_activation): - execfile(virtualenv_activation, dict(__file__=virtualenv_activation)) - -syslog.openlog(os.path.basename(__file__), syslog.LOG_PID, syslog.LOG_USER) - -import django -django.setup() - -# ---------------------------------------------------------------------- - -from ietf.doc.lastcall import get_expired_last_calls, expire_last_call - -drafts = get_expired_last_calls() -for doc in drafts: - try: - expire_last_call(doc) - syslog.syslog("Expired last call for %s (id=%s)" % (doc.file_tag(), doc.pk)) - except Exception as e: - syslog.syslog(syslog.LOG_ERR, "ERROR: Failed to expire last call for %s (id=%s)" % (doc.file_tag(), doc.pk))