diff --git a/public/js/js.js b/public/js/js.js index 2bda58b..99f536f 100755 --- a/public/js/js.js +++ b/public/js/js.js @@ -39,7 +39,7 @@ function init() { } function format(job) { return `
${job.cron} |
diff --git a/scheduler/scheduler.go b/scheduler/scheduler.go
index f4897c5..3647523 100755
--- a/scheduler/scheduler.go
+++ b/scheduler/scheduler.go
@@ -48,11 +48,11 @@ func NewFromFile(config string) (*Scheduler, error) {
if len(line) == 0 {
continue
}
- schedule, command := splitScheduleCommand(line)
+ schedule, command, title := splitScheduleCommandTitle(line)
if len(schedule) == 0 || len(command) == 0 {
continue
}
- job, err := NewJob(Bash, schedule, command)
+ job, err := newBashJob(schedule, command, title)
if err != nil {
logger.New().Error(err, "cannot fully parse file: new job error", config, ", sched", schedule, ", comm", command)
continue
@@ -80,16 +80,20 @@ func cleanLine(b []byte) []byte {
return b
}
-func splitScheduleCommand(b []byte) (string, string) {
+func splitScheduleCommandTitle(b []byte) (string, string, string) {
re := regexp.MustCompile(`^((\d+|\*\/\d+|(\d,)*\d+|\*) [ ]*){5,6}`)
schedule := string(re.Find(b))
if len(schedule) == 0 {
- return "", ""
+ return "", "", ""
}
- command := strings.TrimPrefix(string(b), schedule)
+ commandTitle := strings.TrimPrefix(string(b), schedule)
schedule = strings.TrimSpace(schedule)
- command = strings.TrimSpace(command)
- return schedule, command
+ commandTitle = strings.TrimSpace(commandTitle)
+ title := ""
+ if i := strings.LastIndex(commandTitle, "#"); i >= 0 {
+ title = commandTitle[i+1:]
+ }
+ return schedule, commandTitle, title
}
func (s *Scheduler) Start() error {
diff --git a/scheduler/scheduler_test.go b/scheduler/scheduler_test.go
index 5d7b8bc..66a79db 100755
--- a/scheduler/scheduler_test.go
+++ b/scheduler/scheduler_test.go
@@ -153,3 +153,42 @@ func TestSchedulerFromFile(t *testing.T) {
})
}
}
+
+func TestSplitScheduleCommandTitle(t *testing.T) {
+ cases := map[string]struct {
+ in string
+ schedule string
+ command string
+ title string
+ }{
+ "invalid schedule": {
+ in: "* * * cmd #title",
+ },
+ "no title": {
+ in: "* * * * * cmd ",
+ schedule: "* * * * *",
+ command: "cmd",
+ },
+ "schedule, command, title": {
+ in: "* * * * * cmd #title",
+ schedule: "* * * * *",
+ command: "cmd #title",
+ title: "title",
+ },
+ }
+
+ for name, c := range cases {
+ t.Run(name, func(t *testing.T) {
+ s, a, l := splitScheduleCommandTitle([]byte(c.in))
+ if s != c.schedule {
+ t.Error(s)
+ }
+ if a != c.command {
+ t.Error(a)
+ }
+ if l != c.title {
+ t.Error(l)
+ }
+ })
+ }
+}
diff --git a/server/list.go b/server/list.go
index 2be8ec0..ff270a2 100755
--- a/server/list.go
+++ b/server/list.go
@@ -35,6 +35,7 @@ func (s *Server) list(w http.ResponseWriter, r *http.Request) {
panic(err)
}
out[i]["id"] = j.Name
+ out[i]["title"] = j.Title
out[i]["cron"] = j.Schedule
out[i]["language"] = j.Runner.String()
out[i]["script"] = j.Raw