Jobs & Workflows https://armen.surge.sh
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
armen/internal/cli/jobs.go

109 lines
2.4 KiB

/*
------------------------------------------------------------------------------------------------------------------------
####### cli ####### Copyright (c) 2021 mls-361 ##################################################### MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package cli
import (
"encoding/json"
"errors"
"fmt"
"time"
"forge.chapril.org/armen/jw"
"forge.chapril.org/armen/armen/internal/components"
)
func setPrivate(job *jw.Job, value string) error {
return json.Unmarshal([]byte(value), &job.Private)
}
func setRunAfter(job *jw.Job, value string) error {
t, err := time.Parse(time.RFC3339, value)
if err != nil {
return err
}
job.RunAfter = t
return nil
}
func setCategory(job *jw.Job, value string) error {
if value == "" {
return errors.New("cannot be empty") ///////////////////////////////////////////////////////////////////////////
}
category := new(string)
*category = value
job.Category = category
return nil
}
func jobCreate(ccs *components.Components, args []string) error {
if len(args) < 2 {
help()
return _errArgs
}
fs := newFlagSet(ccs)
job := new(jw.Job)
fs.StringVar(&job.Name, "name", "", "")
fs.StringVar(&job.Namespace, "namespace", "", "")
fs.StringVar(&job.Type, "type", "", "")
fs.StringVar(&job.Origin, "origin", "", "")
fs.IntVar((*int)(&job.Priority), "priority", 0, "")
fs.Func("private", "", func(value string) error { return setPrivate(job, value) })
fs.Func("run_after", "", func(value string) error { return setRunAfter(job, value) })
fs.IntVar(&job.Retries, "retries", 0, "")
fs.Func("category", "", func(value string) error { return setCategory(job, value) })
if err := fs.Parse(args); err != nil {
return err
}
requestor, err := newRequestor(ccs)
if err != nil {
return err
}
job, err = requestor.CreateJob(job)
if err != nil {
return err
}
data, err := json.MarshalIndent(job, "", " ")
if err != nil {
fmt.Printf("%+v\n\n", job)
return err
}
fmt.Println(string(data))
return nil
}
func jobs(ccs *components.Components, args []string) error {
if len(args) < 1 {
help()
return _errArgs
}
switch args[0] {
case "create":
return jobCreate(ccs, args[1:])
default:
help()
}
return nil
}
/*
######################################################################################################## @(°_°)@ #######
*/