don't create unnecessary outage records
@@ -331,9 +331,12 @@ def agent_recovery_sms_task(pk):
@app.task
def agent_outages_task():
- agents = Agent.objects.only("pk")
+ agents = Agent.objects.only(
+ "pk", "last_seen", "overdue_time", "overdue_email_alert", "overdue_text_alert"
+ )
for agent in agents:
+ if agent.overdue_email_alert or agent.overdue_text_alert:
if agent.status == "overdue":
outages = AgentOutage.objects.filter(agent=agent)
if outages and outages.last().is_active:
