Skip to content

Commit

Permalink
refactor(oncall): take an array in withShifts rather than an bject
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-bauer committed Jan 6, 2025
1 parent 10a2487 commit 573a54a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 44 deletions.
43 changes: 21 additions & 22 deletions docs/oncall.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,27 +229,26 @@ declared like:

local calendar = grafanaplane.oncall.schedule.calendar,
local onCallUsers = [['[email protected]'], ['[email protected]']],

primary: calendar.new('Primary', {
weekday: // 24 hour daily shift
calendar.shift.new('Weekday', '2025-01-01T12:00:00', 24 * 60 * 60)
+ calendar.shift.withByDay(['MO', 'TU', 'WE', 'TH', 'FR'])
+ calendar.shift.withRollingUsers('daily', onCallUsers),
weekend: // 72 hour weekend shift
calendar.shift.new('Weekend', '2025-01-01T12:00:00', 72 * 60 * 60)
+ calendar.shift.withByDay(['FR', 'SA', 'SU', 'MO'])
+ calendar.shift.withRollingUsers('weekly', onCallUsers),
}),

secondary: calendar.new('Secondary', {
[shift.key]:
shift.value
// replace the resource ID
+ calendar.shift.withId('secondary-' + shift.value.metadata.name)
// start rotating from the second person
+ calendar.shift.withStartRotationFromUserIndex(1)
primary: calendar.new('Primary', [
// 24 hour daily shift
calendar.shift.new('Weekday', '2025-01-01T12:00:00', 24 * 60 * 60)
+ calendar.shift.withByDay(['MO', 'TU', 'WE', 'TH', 'FR'])
+ calendar.shift.withRollingUsers('daily', onCallUsers),
// 72 hour weekend shift
calendar.shift.new('Weekend', '2025-01-01T12:00:00', 72 * 60 * 60)
+ calendar.shift.withByDay(['FR', 'SA', 'SU', 'MO'])
+ calendar.shift.withRollingUsers('weekly', onCallUsers),
]),

// same as the primary shift, but shifted one person
secondary: calendar.new('Secondary', [
shift
// replace the resource ID
+ calendar.shift.withId('secondary-' + shift.metadata.name)
// start rotating from the second person
+ calendar.shift.withStartRotationFromUserIndex(1)
for shift in std.objectKeysValues(self.primary.shifts)
}),
]),

##### fn schedule.calendar.withId

Expand All @@ -270,9 +269,9 @@ schedule.calendar.withShifts(shifts)

PARAMETERS:

* **shifts** (`object`)
* **shifts** (`array`)

`withShifts` sets a map of Shifts on a calendar-type Schedule.
`withShifts` sets an array of Shifts on a calendar-type Schedule.

##### obj schedule.calendar.shift

Expand Down
43 changes: 21 additions & 22 deletions grafanaplane/oncall/schedule.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,26 @@ local forProvider = schedule.spec.parameters.forProvider;
local calendar = grafanaplane.oncall.schedule.calendar,
local onCallUsers = [['[email protected]'], ['[email protected]']],
primary: calendar.new('Primary', [
// 24 hour daily shift
calendar.shift.new('Weekday', '2025-01-01T12:00:00', 24 * 60 * 60)
+ calendar.shift.withByDay(['MO', 'TU', 'WE', 'TH', 'FR'])
+ calendar.shift.withRollingUsers('daily', onCallUsers),
// 72 hour weekend shift
calendar.shift.new('Weekend', '2025-01-01T12:00:00', 72 * 60 * 60)
+ calendar.shift.withByDay(['FR', 'SA', 'SU', 'MO'])
+ calendar.shift.withRollingUsers('weekly', onCallUsers),
]),
primary: calendar.new('Primary', {
weekday: // 24 hour daily shift
calendar.shift.new('Weekday', '2025-01-01T12:00:00', 24 * 60 * 60)
+ calendar.shift.withByDay(['MO', 'TU', 'WE', 'TH', 'FR'])
+ calendar.shift.withRollingUsers('daily', onCallUsers),
weekend: // 72 hour weekend shift
calendar.shift.new('Weekend', '2025-01-01T12:00:00', 72 * 60 * 60)
+ calendar.shift.withByDay(['FR', 'SA', 'SU', 'MO'])
+ calendar.shift.withRollingUsers('weekly', onCallUsers),
}),
secondary: calendar.new('Secondary', {
[shift.key]:
shift.value
// replace the resource ID
+ calendar.shift.withId('secondary-' + shift.value.metadata.name)
// start rotating from the second person
+ calendar.shift.withStartRotationFromUserIndex(1)
// same as the primary shift, but shifted one person
secondary: calendar.new('Secondary', [
shift
// replace the resource ID
+ calendar.shift.withId('secondary-' + shift.metadata.name)
// start rotating from the second person
+ calendar.shift.withStartRotationFromUserIndex(1)
for shift in std.objectKeysValues(self.primary.shifts)
}),
]),
|||,
[
d.argument.new('name', d.T.string),
Expand All @@ -54,7 +53,7 @@ local forProvider = schedule.spec.parameters.forProvider;
+ forProvider.withType('calendar')
+ forProvider.withShiftsRef([
forProvider.shiftsRef.withName(shift.metadata.name)
for shift in std.objectValues(self.shifts)
for shift in self.shifts
]),
shifts: shifts,
},
Expand All @@ -70,9 +69,9 @@ local forProvider = schedule.spec.parameters.forProvider;

'#withShifts':: d.func.new(
|||
`withShifts` sets a map of Shifts on a calendar-type Schedule.
`withShifts` sets an array of Shifts on a calendar-type Schedule.
|||,
[d.argument.new('shifts', d.T.object)]
[d.argument.new('shifts', d.T.array)]
),
withShifts(shifts):: {
shifts: shifts,
Expand Down

0 comments on commit 573a54a

Please sign in to comment.