maintenance.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # coding: utf-8
  2. from __future__ import print_function
  3. from __future__ import absolute_import
  4. from __future__ import division
  5. from __future__ import unicode_literals
  6. from django.utils.timezone import now
  7. import datetime
  8. from . import models as pmodels
  9. def ping_stuck_processes(stuck_cutoff, audit_author, logdate=None):
  10. from .email import ping_process
  11. if logdate is None: logdate = now()
  12. for process in pmodels.Process.objects.in_early_stage():
  13. already_pinged = False
  14. for idx, entry in enumerate(process.log.order_by("logdate")):
  15. if entry.action == "ping":
  16. already_pinged = True
  17. if entry.logdate > stuck_cutoff: continue
  18. if not already_pinged:
  19. # Detect first instance of processes stuck early: X days from
  20. # last log, no previous ping message
  21. ping_process(audit_author, process, message="""
  22. If nothing happens, the process will be automatically closed a week from now.
  23. """)
  24. process.add_log(audit_author, "looks stuck, pinged", action="ping", logdate=logdate)
  25. else:
  26. # Detect second instance: X days from last log, no
  27. # intent/advocate/sc_dmup, a previous ping message
  28. ping_process(audit_author, process, message="""
  29. A week has passed from the last ping with no action, I'll now close the
  30. process. Feel free to reapply in the future.
  31. """)
  32. process.add_log(audit_author, "closing for inactivity", action="proc_close", logdate=logdate)
  33. process.closed = logdate
  34. process.save()