11package schedule
22
33import (
4- "context"
5-
64 "github.com/robfig/cron/v3"
75 "github.com/rs/zerolog/log"
86 "github.com/spf13/cobra"
@@ -16,7 +14,7 @@ var runCmd = &cobra.Command{
1614 Use : "run" ,
1715 Short : "Run the backup and restore schedules" ,
1816 Long : `Run the backup and restore schedules defined in the configuration file.` ,
19- Run : func (_ * cobra.Command , _ []string ) {
17+ Run : func (cmd * cobra.Command , _ []string ) {
2018 logger := log .Logger .With ().Str ("caller" , "schedule_runner" ).Logger ()
2119
2220 backupCount := len (config .Loaded .Schedule )
@@ -37,15 +35,14 @@ var runCmd = &cobra.Command{
3735
3836 // Register backup schedules
3937 for _ , schedule := range config .Loaded .Schedule {
40- if id , err := c .AddFunc (schedule , func () { internal .Backup (context . Background ()) }); err != nil {
38+ if _ , err := c .AddFunc (schedule , func () { internal .Backup (cmd . Context ()) }); err != nil {
4139 logger .Fatal ().Err (err ).
4240 Str ("cron_expression" , schedule ).
4341 Msg ("failed to register backup schedule - invalid cron expression" )
4442 } else {
4543 logger .Info ().
4644 Str ("type" , "backup" ).
4745 Str ("cron_expression" , schedule ).
48- Str ("next_run" , c .Entry (id ).Next .String ()).
4946 Msg ("schedule registered successfully" )
5047 }
5148 }
@@ -63,8 +60,8 @@ var runCmd = &cobra.Command{
6360
6461 // Create a closure to capture the restore schedule config
6562 scheduleConfig := restoreSchedule // Important: capture the value, not the reference
66- if id , err := c .AddFunc (restoreSchedule .Cron , func () {
67- if err := internal .ScheduledRestore (context . Background (), scheduleConfig ); err != nil {
63+ if _ , err := c .AddFunc (restoreSchedule .Cron , func () {
64+ if err := internal .ScheduledRestore (cmd . Context (), scheduleConfig ); err != nil {
6865 log .Error ().Err (err ).
6966 Str ("cron_expression" , scheduleConfig .Cron ).
7067 Str ("target_database" , scheduleConfig .TargetDatabase ).
@@ -81,7 +78,6 @@ var runCmd = &cobra.Command{
8178 Str ("cron_expression" , restoreSchedule .Cron ).
8279 Str ("target_database" , restoreSchedule .TargetDatabase ).
8380 Str ("backup_selection" , restoreSchedule .BackupSelection ).
84- Str ("next_run" , c .Entry (id ).Next .String ()).
8581 Msg ("schedule registered successfully" )
8682 }
8783 }
0 commit comments