From 4c8799ce8943802b7cbf60ef03c35aa461b07175 Mon Sep 17 00:00:00 2001 From: Fred Date: Mon, 25 Sep 2023 17:04:47 +0100 Subject: [PATCH] fix multi-platform field renaming --- schedule/handler_crond.go | 8 ++++---- schedule/handler_systemd.go | 12 ++++++------ schedule/handler_windows.go | 4 ++-- schtasks/taskscheduler.go | 12 ++++++------ 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/schedule/handler_crond.go b/schedule/handler_crond.go index 07bdff70..b3229ceb 100644 --- a/schedule/handler_crond.go +++ b/schedule/handler_crond.go @@ -61,8 +61,8 @@ func (h *HandlerCrond) CreateJob(job *config.ScheduleConfig, schedules []*calend entries[i] = crond.NewEntry( event, job.ConfigFile, - job.Title, - job.SubTitle, + job.ProfileName, + job.CommandName, job.Command+" "+strings.Join(job.Arguments, " "), job.WorkingDirectory, ) @@ -80,8 +80,8 @@ func (h *HandlerCrond) RemoveJob(job *config.ScheduleConfig, permission string) crond.NewEntry( calendar.NewEvent(), job.ConfigFile, - job.Title, - job.SubTitle, + job.ProfileName, + job.CommandName, job.Command+" "+strings.Join(job.Arguments, " "), job.WorkingDirectory, ), diff --git a/schedule/handler_systemd.go b/schedule/handler_systemd.go index 621d4427..4d23c41a 100644 --- a/schedule/handler_systemd.go +++ b/schedule/handler_systemd.go @@ -109,8 +109,8 @@ func (h *HandlerSystemd) CreateJob(job *config.ScheduleConfig, schedules []*cale CommandLine: job.Command + " --no-prio " + strings.Join(job.Arguments, " "), Environment: job.Environment, WorkingDirectory: job.WorkingDirectory, - Title: job.Title, - SubTitle: job.SubTitle, + Title: job.ProfileName, + SubTitle: job.CommandName, JobDescription: job.JobDescription, TimerDescription: job.TimerDescription, Schedules: job.Schedules, @@ -134,7 +134,7 @@ func (h *HandlerSystemd) CreateJob(job *config.ScheduleConfig, schedules []*cale } } - timerName := systemd.GetTimerFile(job.Title, job.SubTitle) + timerName := systemd.GetTimerFile(job.ProfileName, job.CommandName) // enable the job err = runSystemctlCommand(timerName, systemctlEnable, unitType, false) @@ -164,7 +164,7 @@ func (h *HandlerSystemd) RemoveJob(job *config.ScheduleConfig, permission string unitType = systemd.SystemUnit } var err error - timerFile := systemd.GetTimerFile(job.Title, job.SubTitle) + timerFile := systemd.GetTimerFile(job.ProfileName, job.CommandName) // stop the job err = runSystemctlCommand(timerFile, systemctlStop, unitType, job.RemoveOnly) @@ -191,7 +191,7 @@ func (h *HandlerSystemd) RemoveJob(job *config.ScheduleConfig, permission string return nil } - serviceFile := systemd.GetServiceFile(job.Title, job.SubTitle) + serviceFile := systemd.GetServiceFile(job.ProfileName, job.CommandName) err = os.Remove(path.Join(systemdPath, serviceFile)) if err != nil { return nil @@ -202,7 +202,7 @@ func (h *HandlerSystemd) RemoveJob(job *config.ScheduleConfig, permission string // DisplayJobStatus displays information of a systemd service/timer func (h *HandlerSystemd) DisplayJobStatus(job *config.ScheduleConfig) error { - timerName := systemd.GetTimerFile(job.Title, job.SubTitle) + timerName := systemd.GetTimerFile(job.ProfileName, job.CommandName) permission := getSchedulePermission(job.Permission) if permission == constants.SchedulePermissionSystem { err := runJournalCtlCommand(timerName, systemd.SystemUnit) diff --git a/schedule/handler_windows.go b/schedule/handler_windows.go index f074a211..cb583a6a 100644 --- a/schedule/handler_windows.go +++ b/schedule/handler_windows.go @@ -71,7 +71,7 @@ func (h *HandlerWindows) CreateJob(job *config.ScheduleConfig, schedules []*cale // RemoveJob is deleting the task scheduler job func (h *HandlerWindows) RemoveJob(job *config.ScheduleConfig, permission string) error { - err := schtasks.Delete(job.Title, job.SubTitle) + err := schtasks.Delete(job.ProfileName, job.CommandName) if err != nil { if errors.Is(err, schtasks.ErrorNotRegistered) { return ErrorServiceNotFound @@ -83,7 +83,7 @@ func (h *HandlerWindows) RemoveJob(job *config.ScheduleConfig, permission string // DisplayStatus display some information about the task scheduler job func (h *HandlerWindows) DisplayJobStatus(job *config.ScheduleConfig) error { - err := schtasks.Status(job.Title, job.SubTitle) + err := schtasks.Status(job.ProfileName, job.CommandName) if err != nil { if errors.Is(err, schtasks.ErrorNotRegistered) { return ErrorServiceNotFound diff --git a/schtasks/taskscheduler.go b/schtasks/taskscheduler.go index 327e04dd..6233feed 100644 --- a/schtasks/taskscheduler.go +++ b/schtasks/taskscheduler.go @@ -101,7 +101,7 @@ func Create(config *config.ScheduleConfig, schedules []*calendar.Event, permissi // createUserTask creates a new user task. Will update an existing task instead of overwritting func createUserTask(config *config.ScheduleConfig, schedules []*calendar.Event) error { - taskName := getTaskPath(config.Title, config.SubTitle) + taskName := getTaskPath(config.ProfileName, config.CommandName) registeredTask, err := taskService.GetRegisteredTask(taskName) if err == nil { // the task already exists @@ -145,7 +145,7 @@ func createUserTask(config *config.ScheduleConfig, schedules []*calendar.Event) // updateUserTask updates an existing task func updateUserTask(task taskmaster.RegisteredTask, config *config.ScheduleConfig, schedules []*calendar.Event) error { - taskName := getTaskPath(config.Title, config.SubTitle) + taskName := getTaskPath(config.ProfileName, config.CommandName) username, password, err := userCredentials() if err != nil { @@ -202,7 +202,7 @@ func userCredentials() (string, string, error) { // createUserLoggedOnTask creates a new user task. Will update an existing task instead of overwritting func createUserLoggedOnTask(config *config.ScheduleConfig, schedules []*calendar.Event) error { - taskName := getTaskPath(config.Title, config.SubTitle) + taskName := getTaskPath(config.ProfileName, config.CommandName) registeredTask, err := taskService.GetRegisteredTask(taskName) if err == nil { // the task already exists @@ -240,7 +240,7 @@ func createUserLoggedOnTask(config *config.ScheduleConfig, schedules []*calendar // updateUserLoggedOnTask updates an existing task func updateUserLoggedOnTask(task taskmaster.RegisteredTask, config *config.ScheduleConfig, schedules []*calendar.Event) error { - taskName := getTaskPath(config.Title, config.SubTitle) + taskName := getTaskPath(config.ProfileName, config.CommandName) // clear up all actions and put ours back task.Definition.Actions = make([]taskmaster.Action, 0, 1) @@ -270,7 +270,7 @@ func updateUserLoggedOnTask(task taskmaster.RegisteredTask, config *config.Sched // createSystemTask creates a new system task. Will update an existing task instead of overwritting func createSystemTask(config *config.ScheduleConfig, schedules []*calendar.Event) error { - taskName := getTaskPath(config.Title, config.SubTitle) + taskName := getTaskPath(config.ProfileName, config.CommandName) registeredTask, err := taskService.GetRegisteredTask(taskName) if err == nil { // the task already exists @@ -303,7 +303,7 @@ func createSystemTask(config *config.ScheduleConfig, schedules []*calendar.Event // updateSystemTask updates an existing task func updateSystemTask(task taskmaster.RegisteredTask, config *config.ScheduleConfig, schedules []*calendar.Event) error { - taskName := getTaskPath(config.Title, config.SubTitle) + taskName := getTaskPath(config.ProfileName, config.CommandName) // clear up all actions and put ours back task.Definition.Actions = make([]taskmaster.Action, 0, 1)