diff --git a/docs/oncall.md b/docs/oncall.md index 61204f7..00fee4c 100644 --- a/docs/oncall.md +++ b/docs/oncall.md @@ -227,28 +227,30 @@ Shifts are unordered, and so are supplied as an object to allow for reuse. For example, a Primary/Secondary pair of Schedules could be declared like: - local calendar = grafanaplane.oncall.schedule.calendar, - local onCallUsers = [['bob@example.com'], ['alice@example.com']], - 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) - ]), +```jsonnet +local calendar = grafanaplane.oncall.schedule.calendar, +local onCallUsers = [['bob@example.com'], ['alice@example.com']], +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 self.primary.shifts +]), +``` ##### fn schedule.calendar.withId @@ -337,8 +339,10 @@ together. For example, if - frequency: 'daily', - users: [['alex@example.com', 'bob@example.com'], ['alice@example.com']] +```jsonnet +frequency: 'daily', +users: [['alex@example.com', 'bob@example.com'], ['alice@example.com']] +``` then on the first day, Alex and Bob would both be notified. On the next day, only Alice would be. After that, Alex and Bob again, then Alice, and diff --git a/grafanaplane/oncall/schedule.libsonnet b/grafanaplane/oncall/schedule.libsonnet index 66f79af..c6ee23f 100644 --- a/grafanaplane/oncall/schedule.libsonnet +++ b/grafanaplane/oncall/schedule.libsonnet @@ -17,28 +17,30 @@ local forProvider = schedule.spec.parameters.forProvider; reuse. For example, a Primary/Secondary pair of Schedules could be declared like: - local calendar = grafanaplane.oncall.schedule.calendar, - local onCallUsers = [['bob@example.com'], ['alice@example.com']], - 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), - ]), + ```jsonnet + local calendar = grafanaplane.oncall.schedule.calendar, + local onCallUsers = [['bob@example.com'], ['alice@example.com']], + 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) - ]), + // 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 self.primary.shifts + ]), + ``` |||, [ d.argument.new('name', d.T.string), diff --git a/grafanaplane/oncall/shift.libsonnet b/grafanaplane/oncall/shift.libsonnet index 686ef7c..5a9db80 100644 --- a/grafanaplane/oncall/shift.libsonnet +++ b/grafanaplane/oncall/shift.libsonnet @@ -42,8 +42,10 @@ local forProvider = shift.spec.parameters.forProvider; For example, if - frequency: 'daily', - users: [['alex@example.com', 'bob@example.com'], ['alice@example.com']] + ```jsonnet + frequency: 'daily', + users: [['alex@example.com', 'bob@example.com'], ['alice@example.com']] + ``` then on the first day, Alex and Bob would both be notified. On the next day, only Alice would be. After that, Alex and Bob again, then Alice, and