Add hourly support to custom shifts frequency

This commit is contained in:
Matias Bordese 2022-06-27 17:26:53 -03:00
parent e148d6fc8a
commit 817693b1c0
2 changed files with 8 additions and 3 deletions

View file

@ -53,7 +53,7 @@ The above command returns JSON structured in the following way:
| `level` | No | Optional | Priority level. The higher the value, the higher the priority. If two events overlap in one schedule, Grafana OnCall will choose the event with higher level. For example: Alex is on-call from 8AM till 11AM with level 1, Bob is on-call from 9AM till 11AM with level 2. At 10AM Grafana OnCall will notify Bob. At 8AM OnCall will notify Alex. |
| `start` | No | Yes | Start time of the on-call shift. This parameter takes a date format as `yyyy-MM-dd'T'HH:mm:ss` (for example "2020-09-05T08:00:00"). |
| `duration` | No | Yes | Duration of the event. |
| `frequency` | No | If type = `recurrent_event` or `rolling_users` | One of: `daily`, `weekly`, `monthly`. |
| `frequency` | No | If type = `recurrent_event` or `rolling_users` | One of: `hourly`, `daily`, `weekly`, `monthly`. |
| `interval` | No | Optional | This parameter takes a positive integer that represents the intervals that the recurrence rule repeats. |
| `week_start` | No | Optional | Start day of the week in iCal format. One of: `SU` (Sunday), `MO` (Monday), `TU` (Tuesday), `WE` (Wednesday), `TH` (Thursday), `FR` (Friday), `SA` (Saturday). Default: `SU`. |
| `by_day` | No | Optional | List of days in iCal format. Valid values are: `SU`, `MO`, `TU`, `WE`, `TH`, `FR`, `SA`. |

View file

@ -40,15 +40,18 @@ class CustomOnCallShift(models.Model):
FREQUENCY_DAILY,
FREQUENCY_WEEKLY,
FREQUENCY_MONTHLY,
) = range(3)
FREQUENCY_HOURLY,
) = range(4)
FREQUENCY_CHOICES = (
(FREQUENCY_HOURLY, "Hourly"),
(FREQUENCY_DAILY, "Daily"),
(FREQUENCY_WEEKLY, "Weekly"),
(FREQUENCY_MONTHLY, "Monthly"),
)
PUBLIC_FREQUENCY_CHOICES_MAP = {
FREQUENCY_HOURLY: "hourly",
FREQUENCY_DAILY: "daily",
FREQUENCY_WEEKLY: "weekly",
FREQUENCY_MONTHLY: "monthly",
@ -247,7 +250,9 @@ class CustomOnCallShift(models.Model):
next_event_start = current_event_start
ONE_DAY = 1
if self.frequency == CustomOnCallShift.FREQUENCY_DAILY:
if self.frequency == CustomOnCallShift.FREQUENCY_HOURLY:
next_event_start = current_event_start + timezone.timedelta(hours=1)
elif self.frequency == CustomOnCallShift.FREQUENCY_DAILY:
# test daily with byday
next_event_start = current_event_start + timezone.timedelta(days=ONE_DAY)
elif self.frequency == CustomOnCallShift.FREQUENCY_WEEKLY: