Skip to content

Cron Schedule#14

Open
mobiusdickus wants to merge 24 commits intomoonbeam-nyc:mainfrom
mobiusdickus:cc/cron-schedule
Open

Cron Schedule#14
mobiusdickus wants to merge 24 commits intomoonbeam-nyc:mainfrom
mobiusdickus:cc/cron-schedule

Conversation

@mobiusdickus
Copy link

@mobiusdickus mobiusdickus commented Feb 24, 2025

Overview

Added cron scheduling feature to allow for more complex sleep scheduling.

Changes

  • Created two types of scheduling, DailyWindow and CronSchedule. DailyWindow uses the same logic as the original with a wakeTime and sleepTime in the "3:04pm" format. CronSchedule has a wakeSchedule and a sleepSchedule that follows the typical cron style '* * * * *' format.
  • Added some controller tests to test the new logic i've introduced.
  • Added a SleepScheduleReconciler constructor to allow for easier mocking when testing.
    • Added a clock until to the operator to replace real time with mock time for time Now function.
  • Added new kubebuilder validator logic to enforce oneOf either DailyWindow or CronSchedule.
  • Made Timezone actually optional by removing the kubebuilder validator and allowing the controller logic to use the time.LoadLocation default UTC if no timezone is specified.
  • Removed Now and Location from the SleepScheduleData since Now was not being used and Location redundant to Timezone in its application.

Notes

  • I'm using gronx for cron operations.
  • Added controller logic to ensure one of the two schedule types are defined, which makes it necessary to add in tests since it can't be ignored like the other kubebuilder validators.
  • When using CronSchedule, if two times (wake and sleep) are the same, it implicitly defaults to being awake.
  • When using DailyWindow, if two times (wake and sleep) are the same, it implicitly defaults to being asleep. (although this is very unlikely/makes little sense, there is currently nothing preventing someone from doing this)

Suggestions

  • Currently DailyWindow does not support military time and only "3:04pm" format, but we can easily add to the time formats accepted to make this more flexible. (e.g. 15:04, 3:04 PM, etc...)
  • Add mock deployments to tests to test actual state change.
  • If merged, you might want to change the main README screen recording.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant