-
Notifications
You must be signed in to change notification settings - Fork 299
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
Update schedule slack notifications #2710
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
A few comments added.
Great you added more tests covering different notification trigger (or not) scenarios 👍
And really nice to see the notify task simplification!
gaps = list_of_gaps_in_schedule(schedule, today, today + timezone.timedelta(days=7)) | ||
schedule.gaps_report_sent_at = today | ||
now = timezone.now() | ||
events = schedule.final_events(now, now + datetime.timedelta(days=7), with_empty=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to set with_empty=False
here? final_events
will still return gaps if there are any, won't it? (and empty shifts should be detected by the respective task, right?)
Also, could we use the check_gaps_for_next_week
method from schedule in this case? (I see it may require some refactoring to reuse it here, maybe for a next PR)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, we can filter it in the task. It makes sense since we need to filer the output anyway.
I think, if we change using of check_gaps_for_next_week
we should also change using check_empty_shifts_for_next_week
since they have pretty similar logic. I would propose to do it in separate PR
gaps = list_of_gaps_in_schedule(self, today, today + datetime.timedelta(days=7)) | ||
def check_gaps_for_next_week(self) -> bool: | ||
today = timezone.now() | ||
events = self.final_events(today, today + datetime.timedelta(days=7), False, True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar as noted below, wondering if if/why we need to pass with_empty=False
here.
Also, I think it would be clearer setting these flags as kw args make it easier to understand what we are filtering at a quick glance.
@@ -396,9 +398,11 @@ def filter_events( | |||
|
|||
return events | |||
|
|||
def final_events(self, datetime_start, datetime_end): | |||
def final_events(self, datetime_start, datetime_end, with_empty=True, with_gap=True): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How sure are that we need to enable these flags here? I would really like (to believe?) that when checking final events, we are interested in the final schedule events only, without needing to tune the options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's mostly needed for slack notifications about new/next shifts. We need only shifts without gaps and empties there. We already have logic to filter such kind of events in filter_events
and it makes notify_ical_schedule_shift
cleaner.
on_call_shift.add_rolling_users([[user1]]) | ||
schedule_no_gaps.refresh_ical_file() | ||
|
||
assert schedule_no_gaps.check_gaps_for_next_week() is False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe these check_gaps_for_next_week
checks could be added to the previous test cases? (and then we may not need all the variations below which check almost the same scenarios that above?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense 👍
|
||
|
||
@pytest.mark.django_db | ||
def test_empty_non_empty_shifts_trigger_notification( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this is the original behavior, but wondering if this should be a warning in the schedule UI but not triggering a notification (since there is still an active user for the shift). In any case, something to discuss later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, we should discuss it later. I think, the main point is make customer know that something is wrong with one of their shifts despite the presence of an active user.
|
||
prev_shifts = json.loads(schedule.current_shifts) if not schedule.empty_oncall else [] | ||
prev_shifts_updated = False | ||
# convert prev_shifts to new events format for compatibility with the previous version of this task |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be nice to leave a task for later to drop this conversion. Optional, if you think it makes sense, I would separate this "translation" in a helper function in this module (so it is simpler to follow the task logic ignoring this compatibility thing)
|
||
datetime_end = now + datetime.timedelta(days=days_to_lookup) | ||
|
||
next_shifts_unfiltered = schedule.final_events(now, datetime_end, False, False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not now, but maybe we could consider having only one call to final_events
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be great, but in this case we need to decide how to calculate days_to_lookup
if now < next_shift["start"]: | ||
next_shifts.append(next_shift) | ||
|
||
next_shifts = sorted(next_shifts, key=lambda shift: shift["start"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final_events
should already return events sorted by shift["start"]
schedule.empty_oncall = True | ||
else: | ||
schedule.empty_oncall = False | ||
schedule.current_shifts = json.dumps(current_shifts, default=str) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, I think this could be changed to something like
schedule.empty_oncall = len(current_shifts) == 0
if not schedule.empty_oncall:
schedule.current_shifts = json.dumps(current_shifts, default=str)
?
# Conflicts: # CHANGELOG.md # engine/apps/schedules/models/on_call_schedule.py # engine/apps/schedules/tasks/notify_about_gaps_in_schedule.py # engine/apps/slack/scenarios/schedules.py
What this PR does
Update schedule slack notifications to use schedule final events instead of getting events from iCal
Checklist
pr:no public docs
PR label added if not required)CHANGELOG.md
updated (orpr:no changelog
PR label added if not required)