Wrong unmarshalNewJob when create a remote job by webui build-in
kn1011 opened this issue · comments
kn1011 commented
i create a remote job by webui like this
and i got error log below.
INFO[0000] Job test-create-job-by-web-ui-001:6a57c82e-45e9-40fc-5029-e3bcfd08ad7c added to cache.
INFO[0000] Starting server on port :8000
INFO[0028] {"name":"test023","type":1,"owner":"ss.btm@triott.com","schedule":"R/2022-10-12T20:12:16.828696-08:00/PT10S","retries":0,"url":"http://127.0.0.1:8888/shell/run","method":"GET","headers":{},"body":"{}","timeout":0,"expected_response_codes":[]}
ERRO[0028] Invalid Remote Job. Job's must contain a Name and a url field
ERRO[0028] Error occurred when initializing the job: Invalid Remote Job. Job's must contain a Name and a url field
ERRO[0029] Error occurred when trying to get the job you requested.
the struct of json sent by webui dosen't match the struct of Job below,
type Job struct {
Name string `json:"name"`
Id string `json:"id"`
// Command to run
// e.g. "bash /path/to/my/script.sh"
Command string `json:"command"`
// Email of the owner of this job
// e.g. "admin@example.com"
Owner string `json:"owner"`
// Is this job disabled?
Disabled bool `json:"disabled"`
// Jobs that are dependent upon this one will be run after this job runs.
DependentJobs []string `json:"dependent_jobs"`
// List of ids of jobs that this job is dependent upon.
ParentJobs []string `json:"parent_jobs"`
// Job that gets run after all retries have failed consecutively
OnFailureJob string `json:"on_failure_job"`
// ISO 8601 String
// e.g. "R/2014-03-08T20:00:00.000Z/PT2H"
Schedule string `json:"schedule"`
scheduleTime time.Time
// ISO 8601 Duration struct, used for scheduling
// job after each run.
delayDuration *iso8601.Duration
// Number of times to schedule this job after the
// first run.
timesToRepeat int64
// Number of times to retry on failed attempt for each run.
Retries uint `json:"retries"`
// Duration in which it is safe to retry the Job.
Epsilon string `json:"epsilon"`
epsilonDuration *iso8601.Duration
jobTimer clock.Timer
NextRunAt time.Time `json:"next_run_at"`
// Templating delimiters, the left & right separated by space,
// for example `{{ }}` or `${ }`.
//
// If this field is non-empty, then each time this
// job is executed, Kala will template its main
// content as a Go Template with the job itself as data.
//
// The Command is templated for local jobs,
// and Url and Body in RemoteProperties.
TemplateDelimiters string
// The clock for this job; used to mock time during tests.
clk Clock
// If the job is disabled (or the system inoperative) and we pass
// the scheduled run point, when the job becomes active again,
// normally the job will run immediately.
// With this setting on, it will not run immediately, but will wait
// until the next scheduled run time comes along.
ResumeAtNextScheduledTime bool `json:"resume_at_next_scheduled_time"`
// Meta data about successful and failed runs.
Metadata Metadata `json:"metadata"`
// Type of the job
JobType jobType `json:"type"`
// Custom properties for the remote job type
RemoteProperties RemoteProperties `json:"remote_properties"`
// Collection of Job Stats
Stats []*JobStat `json:"stats"`
lock sync.RWMutex
// Says if a job has been executed right numbers of time
// and should not been executed again in the future
IsDone bool `json:"is_done"`
// The job will send on this channel when it's done running; used for tests.
// Note that if the job should be rescheduled, it will send on this channel
// when it's done rescheduling rather than when the job is done running.
// That's most useful for testing the scheduling aspect of jobs.
ranChan chan struct{}
// Used for testing schedules.
succeedInstantly bool
}
...
// RemoteProperties Custom properties for the remote job type
type RemoteProperties struct {
Url string `json:"url"`
Method string `json:"method"`
// A body to attach to the http request
Body string `json:"body"`
// A list of headers to add to http request (e.g. [{"key": "charset", "value": "UTF-8"}])
Headers http.Header `json:"headers"`
// A timeout property for the http request in seconds
Timeout int `json:"timeout"`
// A list of expected response codes (e.g. [200, 201])
ExpectedResponseCodes []int `json:"expected_response_codes"`
}
...
json of remote job should looks like this
{"name":"test023","type":1,"owner":"ss.btm@triott.com","schedule":"R/2022-10-12T20:12:16.828696-08:00/PT10S","retries":0,"remote_properties":{"url":"http://127.0.0.1:8888/shell/run","method":"GET","headers":{},"body":"{}","timeout":0,"expected_response_codes":[]}}
Matt Mc commented
A PR on this would be welcome.