chore: remove single-use repair_dead_on_expire task (#8348)
* chore: remove single-use repair_dead_on_expire task * fix: remove repair_dead_on_expire * chore: remove abandoned imports
This commit is contained in:
parent
8cadc6988f
commit
8b7fa1199a
|
@ -13,10 +13,10 @@ from pathlib import Path
|
||||||
|
|
||||||
from typing import List, Optional # pyflakes:ignore
|
from typing import List, Optional # pyflakes:ignore
|
||||||
|
|
||||||
from ietf.doc.utils import new_state_change_event, update_action_holders
|
from ietf.doc.utils import update_action_holders
|
||||||
from ietf.utils import log
|
from ietf.utils import log
|
||||||
from ietf.utils.mail import send_mail
|
from ietf.utils.mail import send_mail
|
||||||
from ietf.doc.models import Document, DocEvent, State, StateDocEvent
|
from ietf.doc.models import Document, DocEvent, State
|
||||||
from ietf.person.models import Person
|
from ietf.person.models import Person
|
||||||
from ietf.meeting.models import Meeting
|
from ietf.meeting.models import Meeting
|
||||||
from ietf.mailtrigger.utils import gather_address_lists
|
from ietf.mailtrigger.utils import gather_address_lists
|
||||||
|
@ -235,41 +235,3 @@ def clean_up_draft_files():
|
||||||
# All uses of this past 2014 seem related to major system failures.
|
# All uses of this past 2014 seem related to major system failures.
|
||||||
move_file_to("unknown_ids")
|
move_file_to("unknown_ids")
|
||||||
|
|
||||||
|
|
||||||
def repair_dead_on_expire():
|
|
||||||
by = Person.objects.get(name="(System)")
|
|
||||||
id_exists = State.objects.get(type="draft-iesg", slug="idexists")
|
|
||||||
dead = State.objects.get(type="draft-iesg", slug="dead")
|
|
||||||
dead_drafts = Document.objects.filter(
|
|
||||||
states__type="draft-iesg", states__slug="dead", type_id="draft"
|
|
||||||
)
|
|
||||||
for d in dead_drafts:
|
|
||||||
dead_event = d.latest_event(
|
|
||||||
StateDocEvent, state_type="draft-iesg", state__slug="dead"
|
|
||||||
)
|
|
||||||
if dead_event is not None:
|
|
||||||
if d.docevent_set.filter(type="expired_document").exists():
|
|
||||||
closest_expiry = min(
|
|
||||||
[
|
|
||||||
abs(e.time - dead_event.time)
|
|
||||||
for e in d.docevent_set.filter(type="expired_document")
|
|
||||||
]
|
|
||||||
)
|
|
||||||
if closest_expiry.total_seconds() < 60:
|
|
||||||
d.set_state(id_exists)
|
|
||||||
events = []
|
|
||||||
e = DocEvent(
|
|
||||||
doc=d,
|
|
||||||
rev=d.rev,
|
|
||||||
type="added_comment",
|
|
||||||
by=by,
|
|
||||||
desc="IESG Dead state was set due only to document expiry - changing IESG state to ID-Exists",
|
|
||||||
)
|
|
||||||
e.skip_community_list_notification = True
|
|
||||||
e.save()
|
|
||||||
events.append(e)
|
|
||||||
e = new_state_change_event(d, by, dead, id_exists)
|
|
||||||
e.skip_community_list_notification = True
|
|
||||||
e.save()
|
|
||||||
events.append(e)
|
|
||||||
d.save_with_history(events)
|
|
||||||
|
|
|
@ -18,7 +18,6 @@ from .expire import (
|
||||||
in_draft_expire_freeze,
|
in_draft_expire_freeze,
|
||||||
get_expired_drafts,
|
get_expired_drafts,
|
||||||
expirable_drafts,
|
expirable_drafts,
|
||||||
repair_dead_on_expire,
|
|
||||||
send_expire_notice_for_draft,
|
send_expire_notice_for_draft,
|
||||||
expire_draft,
|
expire_draft,
|
||||||
clean_up_draft_files,
|
clean_up_draft_files,
|
||||||
|
@ -62,11 +61,6 @@ def expire_ids_task():
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
@shared_task
|
|
||||||
def repair_dead_on_expire_task():
|
|
||||||
repair_dead_on_expire()
|
|
||||||
|
|
||||||
|
|
||||||
@shared_task
|
@shared_task
|
||||||
def notify_expirations_task(notify_days=14):
|
def notify_expirations_task(notify_days=14):
|
||||||
for doc in get_soon_to_expire_drafts(notify_days):
|
for doc in get_soon_to_expire_drafts(notify_days):
|
||||||
|
|
|
@ -19,10 +19,10 @@ from django.utils.html import escape
|
||||||
|
|
||||||
import debug # pyflakes:ignore
|
import debug # pyflakes:ignore
|
||||||
|
|
||||||
from ietf.doc.expire import expirable_drafts, get_expired_drafts, repair_dead_on_expire, send_expire_notice_for_draft, expire_draft
|
from ietf.doc.expire import expirable_drafts, get_expired_drafts, send_expire_notice_for_draft, expire_draft
|
||||||
from ietf.doc.factories import EditorialDraftFactory, IndividualDraftFactory, StateDocEventFactory, WgDraftFactory, RgDraftFactory, DocEventFactory
|
from ietf.doc.factories import EditorialDraftFactory, IndividualDraftFactory, WgDraftFactory, RgDraftFactory, DocEventFactory
|
||||||
from ietf.doc.models import ( Document, DocReminder, DocEvent,
|
from ietf.doc.models import ( Document, DocReminder, DocEvent,
|
||||||
ConsensusDocEvent, LastCallDocEvent, RelatedDocument, State, StateDocEvent, TelechatDocEvent,
|
ConsensusDocEvent, LastCallDocEvent, RelatedDocument, State, TelechatDocEvent,
|
||||||
WriteupDocEvent, DocRelationshipName, IanaExpertDocEvent )
|
WriteupDocEvent, DocRelationshipName, IanaExpertDocEvent )
|
||||||
from ietf.doc.utils import get_tags_for_stream_id, create_ballot_if_not_open
|
from ietf.doc.utils import get_tags_for_stream_id, create_ballot_if_not_open
|
||||||
from ietf.doc.views_draft import AdoptDraftForm
|
from ietf.doc.views_draft import AdoptDraftForm
|
||||||
|
@ -36,7 +36,7 @@ from ietf.iesg.models import TelechatDate
|
||||||
from ietf.utils.test_utils import login_testing_unauthorized
|
from ietf.utils.test_utils import login_testing_unauthorized
|
||||||
from ietf.utils.mail import outbox, empty_outbox, get_payload_text
|
from ietf.utils.mail import outbox, empty_outbox, get_payload_text
|
||||||
from ietf.utils.test_utils import TestCase
|
from ietf.utils.test_utils import TestCase
|
||||||
from ietf.utils.timezone import date_today, datetime_today, datetime_from_date, DEADLINE_TZINFO
|
from ietf.utils.timezone import date_today, datetime_from_date, DEADLINE_TZINFO
|
||||||
|
|
||||||
|
|
||||||
class ChangeStateTests(TestCase):
|
class ChangeStateTests(TestCase):
|
||||||
|
@ -845,77 +845,6 @@ class ExpireIDsTests(DraftFileMixin, TestCase):
|
||||||
self.assertTrue(not os.path.exists(os.path.join(settings.INTERNET_DRAFT_PATH, txt)))
|
self.assertTrue(not os.path.exists(os.path.join(settings.INTERNET_DRAFT_PATH, txt)))
|
||||||
self.assertTrue(os.path.exists(os.path.join(settings.INTERNET_DRAFT_ARCHIVE_DIR, txt)))
|
self.assertTrue(os.path.exists(os.path.join(settings.INTERNET_DRAFT_ARCHIVE_DIR, txt)))
|
||||||
|
|
||||||
@mock.patch("ietf.community.signals.notify_of_event")
|
|
||||||
def test_repair_dead_on_expire(self, mock_notify):
|
|
||||||
|
|
||||||
# Create a draft in iesg idexists - ensure it doesn't get new docevents.
|
|
||||||
# Create a draft in iesg dead with no expires within the window - ensure it doesn't get new docevents and its state doesn't change.
|
|
||||||
# Create a draft in iesg dead with an expiry in the window - ensure it gets the right doc events, iesg state changes, draft state doesn't change.
|
|
||||||
last_year = datetime_today() - datetime.timedelta(days=365)
|
|
||||||
|
|
||||||
not_dead = WgDraftFactory(name="draft-not-dead")
|
|
||||||
not_dead_event_count = not_dead.docevent_set.count()
|
|
||||||
|
|
||||||
dead_not_from_expires = WgDraftFactory(name="draft-dead-not-from-expiring")
|
|
||||||
dead_not_from_expires.set_state(
|
|
||||||
State.objects.get(type="draft-iesg", slug="dead")
|
|
||||||
)
|
|
||||||
StateDocEventFactory(
|
|
||||||
doc=dead_not_from_expires, state=("draft-iesg", "dead"), time=last_year
|
|
||||||
)
|
|
||||||
DocEventFactory(
|
|
||||||
doc=dead_not_from_expires,
|
|
||||||
type="expired_document",
|
|
||||||
time=last_year + datetime.timedelta(days=1),
|
|
||||||
)
|
|
||||||
dead_not_from_expires_event_count = dead_not_from_expires.docevent_set.count()
|
|
||||||
|
|
||||||
dead_from_expires = []
|
|
||||||
dead_from_expires_event_count = dict()
|
|
||||||
for delta in [-5, 5]:
|
|
||||||
d = WgDraftFactory(
|
|
||||||
name=f"draft-dead-from-expiring-just-{'before' if delta<0 else 'after'}"
|
|
||||||
)
|
|
||||||
d.set_state(State.objects.get(type="draft-iesg", slug="dead"))
|
|
||||||
StateDocEventFactory(doc=d, state=("draft-iesg", "dead"), time=last_year)
|
|
||||||
DocEventFactory(
|
|
||||||
doc=d,
|
|
||||||
type="expired_document",
|
|
||||||
time=last_year + datetime.timedelta(seconds=delta),
|
|
||||||
)
|
|
||||||
dead_from_expires.append(d)
|
|
||||||
dead_from_expires_event_count[d] = d.docevent_set.count()
|
|
||||||
|
|
||||||
notified_during_factory_work = mock_notify.call_count
|
|
||||||
for call_args in mock_notify.call_args_list:
|
|
||||||
e = call_args.args[0]
|
|
||||||
self.assertTrue(isinstance(e,DocEvent))
|
|
||||||
self.assertFalse(hasattr(e,"skip_community_list_notification"))
|
|
||||||
|
|
||||||
repair_dead_on_expire()
|
|
||||||
|
|
||||||
self.assertEqual(not_dead.docevent_set.count(), not_dead_event_count)
|
|
||||||
self.assertEqual(
|
|
||||||
dead_not_from_expires.docevent_set.count(),
|
|
||||||
dead_not_from_expires_event_count,
|
|
||||||
)
|
|
||||||
for d in dead_from_expires:
|
|
||||||
self.assertEqual(
|
|
||||||
d.docevent_set.count(), dead_from_expires_event_count[d] + 2
|
|
||||||
)
|
|
||||||
self.assertIn(
|
|
||||||
"due only to document expiry", d.latest_event(type="added_comment").desc
|
|
||||||
)
|
|
||||||
self.assertEqual(
|
|
||||||
d.latest_event(StateDocEvent).desc,
|
|
||||||
"IESG state changed to <b>I-D Exists</b> from Dead",
|
|
||||||
)
|
|
||||||
self.assertEqual(mock_notify.call_count, 4+notified_during_factory_work)
|
|
||||||
for call_args in mock_notify.call_args_list[-4:]:
|
|
||||||
e = call_args.args[0]
|
|
||||||
self.assertTrue(isinstance(e,DocEvent))
|
|
||||||
self.assertTrue(hasattr(e,"skip_community_list_notification"))
|
|
||||||
self.assertTrue(e.skip_community_list_notification)
|
|
||||||
|
|
||||||
class ExpireLastCallTests(TestCase):
|
class ExpireLastCallTests(TestCase):
|
||||||
def test_expire_last_call(self):
|
def test_expire_last_call(self):
|
||||||
|
|
|
@ -21,7 +21,6 @@ from .tasks import (
|
||||||
generate_idnits2_rfcs_obsoleted_task,
|
generate_idnits2_rfcs_obsoleted_task,
|
||||||
generate_idnits2_rfc_status_task,
|
generate_idnits2_rfc_status_task,
|
||||||
notify_expirations_task,
|
notify_expirations_task,
|
||||||
repair_dead_on_expire_task,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
class TaskTests(TestCase):
|
class TaskTests(TestCase):
|
||||||
|
@ -99,10 +98,6 @@ class TaskTests(TestCase):
|
||||||
self.assertEqual(mock_expire.call_args_list[1], mock.call(docs[1]))
|
self.assertEqual(mock_expire.call_args_list[1], mock.call(docs[1]))
|
||||||
self.assertEqual(mock_expire.call_args_list[2], mock.call(docs[2]))
|
self.assertEqual(mock_expire.call_args_list[2], mock.call(docs[2]))
|
||||||
|
|
||||||
@mock.patch("ietf.doc.tasks.repair_dead_on_expire")
|
|
||||||
def test_repair_dead_on_expire_task(self, mock_repair):
|
|
||||||
repair_dead_on_expire_task()
|
|
||||||
self.assertEqual(mock_repair.call_count, 1)
|
|
||||||
|
|
||||||
class Idnits2SupportTests(TestCase):
|
class Idnits2SupportTests(TestCase):
|
||||||
settings_temp_path_overrides = TestCase.settings_temp_path_overrides + ['DERIVED_DIR']
|
settings_temp_path_overrides = TestCase.settings_temp_path_overrides + ['DERIVED_DIR']
|
||||||
|
|
Loading…
Reference in a new issue