From 577ed27f1bb060080d311342047e31943a02ccbb Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Thu, 18 May 2017 15:05:57 -0400 Subject: PLT-6408 Framework for job server (#6404) * Added initial job server * Added job server to be ran as part of platform * Added test job to the enterprise repo * Fixed job server not loading license * Renamed job package to jobs * Fixed TE not being buildable * Added JobStatus table to database * Changed fields used by JobStatus * Added APIs to query job status * Added config change listener to server * Added option to run job server from Makefile * Added ability to enable/disable jobs from config * Commented out placeholder for search indexing job * Fixed govet * Removed debug messages and fixed job api init message --- model/client4.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'model/client4.go') diff --git a/model/client4.go b/model/client4.go index f4a247e12..28434c2e5 100644 --- a/model/client4.go +++ b/model/client4.go @@ -254,6 +254,10 @@ func (c *Client4) GetOpenGraphRoute() string { return fmt.Sprintf("/opengraph") } +func (c *Client4) GetJobsRoute() string { + return fmt.Sprintf("/jobs") +} + func (c *Client4) DoApiGet(url string, etag string) (*http.Response, *AppError) { return c.DoApiRequest(http.MethodGet, c.ApiUrl+url, "", etag) } @@ -2638,3 +2642,25 @@ func (c *Client4) OpenGraph(url string) (map[string]string, *Response) { return MapFromJson(r.Body), BuildResponse(r) } } + +// Jobs Section + +// GetJobStatus gets the status of a single job. +func (c *Client4) GetJobStatus(id string) (*JobStatus, *Response) { + if r, err := c.DoApiGet(c.GetJobsRoute()+fmt.Sprintf("/%v/status", id), ""); err != nil { + return nil, &Response{StatusCode: r.StatusCode, Error: err} + } else { + defer closeBody(r) + return JobStatusFromJson(r.Body), BuildResponse(r) + } +} + +// GetJobStatusesByType gets the status of all jobs of a given type, sorted with the job that most recently started first. +func (c *Client4) GetJobStatusesByType(jobType string, page int, perPage int) ([]*JobStatus, *Response) { + if r, err := c.DoApiGet(c.GetJobsRoute()+fmt.Sprintf("/type/%v/statuses?page=%v&per_page=%v", jobType, page, perPage), ""); err != nil { + return nil, &Response{StatusCode: r.StatusCode, Error: err} + } else { + defer closeBody(r) + return JobStatusesFromJson(r.Body), BuildResponse(r) + } +} -- cgit v1.2.3-1-g7c22