@@ -50,6 +50,7 @@ func setupRouter(s *Schedule) *httprouter.Router {
50
50
router .GET ("/api/jobs/:jobId/runs/:jobRunId" , getJobRun (s ))
51
51
router .POST ("/api/jobs/:jobId/trigger" , postTrigger (s ))
52
52
router .GET ("/api/core/logs" , getCoreLogs (s ))
53
+ router .GET ("/api/schedule/status" , getScheduleStatus (s ))
53
54
54
55
fileServer := http .FileServer (http .FS (fsys ()))
55
56
router .GET ("/static/*filepath" , func (w http.ResponseWriter , r * http.Request , _ httprouter.Params ) {
@@ -140,6 +141,36 @@ func getJobs(s *Schedule) httprouter.Handle {
140
141
}
141
142
}
142
143
144
+ type ScheduleStatusResponse struct {
145
+ Status map [string ]int `json:"status,omitempty"`
146
+ FailedRunCount int `json:"failed_run_count,omitempty"`
147
+ HasFailedRuns bool `json:"has_failed_runs,omitempty"`
148
+ }
149
+
150
+ func getScheduleStatus (s * Schedule ) httprouter.Handle {
151
+ return func (w http.ResponseWriter , r * http.Request , _ httprouter.Params ) {
152
+ w .Header ().Set ("Content-Type" , "application/json" )
153
+
154
+ ssr := ScheduleStatusResponse {
155
+ Status : make (map [string ]int , len (s .Jobs )),
156
+ }
157
+ for _ , j := range s .Jobs {
158
+ j .loadRunsFromDb (1 , false )
159
+ lastRunStatus := j .Runs [0 ].Status
160
+ ssr .Status [j .Name ] = lastRunStatus
161
+ if lastRunStatus == 1 {
162
+ ssr .FailedRunCount ++
163
+ }
164
+ }
165
+
166
+ ssr .HasFailedRuns = ssr .FailedRunCount > 0
167
+
168
+ if err := json .NewEncoder (w ).Encode (ssr ); err != nil {
169
+ http .Error (w , err .Error (), http .StatusInternalServerError )
170
+ }
171
+ }
172
+ }
173
+
143
174
func getCoreLogs (s * Schedule ) httprouter.Handle {
144
175
return func (w http.ResponseWriter , r * http.Request , _ httprouter.Params ) {
145
176
w .Header ().Set ("Content-Type" , "application/json" )
0 commit comments