@@ -162,6 +162,13 @@ module Make (R : Renderer) = struct
162
162
String. compare (R.Pipeline.Source. id a) (R.Pipeline.Source. id b)
163
163
end )
164
164
165
+ module SourceSet = Set. Make (struct
166
+ type t = R.Pipeline.Source .t
167
+
168
+ let compare a b =
169
+ String. compare (R.Pipeline.Source. id a) (R.Pipeline.Source. id b)
170
+ end )
171
+
165
172
type pipeline_state =
166
173
(R.Output .t , R.Node .t , R.Stage .t , R.Pipeline .t ) State .pipeline
167
174
@@ -178,7 +185,10 @@ module Make (R : Renderer) = struct
178
185
pipeline_metadata )
179
186
State .pipeline
180
187
181
- type t = pipeline_state_internal StringMap .t SourceMap .t ref
188
+ type t = {
189
+ mutable runs : pipeline_state_internal StringMap .t SourceMap .t ;
190
+ mutable active : SourceSet .t ;
191
+ }
182
192
183
193
let unmarshal =
184
194
State. unmarshal R.Output. unmarshal R.Node. unmarshal R.Stage. unmarshal
@@ -235,25 +245,25 @@ module Make (R : Renderer) = struct
235
245
(k, List. to_seq pipelines |> StringMap. of_seq))
236
246
|> List. to_seq |> SourceMap. of_seq
237
247
in
238
- ref init_state
248
+ { runs = init_state; active = SourceSet. empty }
239
249
240
250
let get ~pipeline_source ~pipeline_id (state : t ) =
241
- match SourceMap. find_opt pipeline_source ! state with
251
+ match SourceMap. find_opt pipeline_source state.runs with
242
252
| None -> None
243
253
| Some v -> StringMap. find_opt pipeline_id v
244
254
245
255
let set ~pipeline_source ~pipeline_id (state : t ) new_state =
246
- match SourceMap. find_opt pipeline_source ! state with
256
+ match SourceMap. find_opt pipeline_source state.runs with
247
257
| None ->
248
- state :=
258
+ state.runs < -
249
259
SourceMap. add pipeline_source
250
260
(StringMap. singleton pipeline_id new_state)
251
- ! state
261
+ state.runs
252
262
| Some v ->
253
- state :=
263
+ state.runs < -
254
264
SourceMap. add pipeline_source
255
265
((StringMap. add pipeline_id new_state) v)
256
- ! state
266
+ state.runs
257
267
258
268
let update_state (state : t ) (new_state : pipeline_state Current.t ) =
259
269
let open Current.Syntax in
@@ -286,6 +296,13 @@ module Make (R : Renderer) = struct
286
296
{ v with metadata = { user_meta; run_time; creation_date } }
287
297
in
288
298
set ~pipeline_source ~pipeline_id state new_state
299
+
300
+ let set_active_sources (state : t )
301
+ (active_sources : R.Pipeline.Source.t list Current.t ) =
302
+ let open Current.Syntax in
303
+ let + active_sources = active_sources in
304
+ state.active < - SourceSet. of_list active_sources
305
+
289
306
(* RENDERING *)
290
307
291
308
let emoji_of_status =
@@ -313,8 +330,18 @@ module Make (R : Renderer) = struct
313
330
314
331
let node_map_status (node_meta , _ ) = R.Node. map_status node_meta
315
332
316
- let list_pipelines ~(state : t ) =
333
+ let list_pipelines ctx ~(state : t ) =
317
334
let open Tyxml_html in
335
+ let list_all_query_param =
336
+ (* this query parameter controls if we list all the pipeline sources for a given group *)
337
+ let uri = Current_web.Context. request ctx |> Cohttp.Request. uri in
338
+ Uri. get_query_param uri " list_all"
339
+ in
340
+ let list_all =
341
+ match list_all_query_param with
342
+ | None -> fun _ -> false
343
+ | Some v -> fun group_id -> R.Pipeline.Group. id group_id = v
344
+ in
318
345
let show_pipeline (pipeline : pipeline_state_internal ) =
319
346
let { user_meta; run_time; _ } = pipeline.metadata in
320
347
let id = R.Pipeline. id user_meta in
@@ -342,25 +369,61 @@ module Make (R : Renderer) = struct
342
369
show_pipeline latest
343
370
in
344
371
[ div [ R. render_index () ]; h2 [ txt " Pipelines" ] ]
345
- @ (SourceMap. bindings ! state
372
+ @ (SourceMap. bindings state.runs
346
373
|> List. sort (fun (a , _ ) (b , _ ) -> R.Pipeline.Source. compare a b)
347
374
|> List. map (fun (source , pipelines ) ->
348
375
(R.Pipeline.Source. group source, (source, pipelines)))
349
376
|> group_by_key R.Pipeline.Group. id
350
377
|> List. map (fun (group , sources ) ->
351
- div
352
- [
353
- h3 [ txt (R.Pipeline.Group. to_string group) ];
354
- ul
355
- (List. map
356
- (fun (_ , pipelines ) -> li (render_source pipelines))
357
- sources);
358
- ]))
378
+ if list_all group then
379
+ div
380
+ [
381
+ h3 [ txt (R.Pipeline.Group. to_string group) ];
382
+ h4 [ i [ txt " active pipelines" ] ];
383
+ ul
384
+ (sources
385
+ |> List. filter (fun (source , _ ) ->
386
+ SourceSet. mem source state.active)
387
+ |> List. map (fun (_ , pipelines ) ->
388
+ li (render_source pipelines)));
389
+ h4 [ i [ a ~a: [ a_href " ?" ] [ txt " inactive pipelines" ] ] ];
390
+ ul
391
+ (sources
392
+ |> List. filter (fun (source , _ ) ->
393
+ not (SourceSet. mem source state.active))
394
+ |> List. map (fun (_ , pipelines ) ->
395
+ li (render_source pipelines)));
396
+ ]
397
+ else
398
+ div
399
+ [
400
+ h3 [ txt (R.Pipeline.Group. to_string group) ];
401
+ h4 [ i [ txt " active pipelines" ] ];
402
+ ul
403
+ (sources
404
+ |> List. filter (fun (source , _ ) ->
405
+ SourceSet. mem source state.active)
406
+ |> List. map (fun (_ , pipelines ) ->
407
+ li (render_source pipelines)));
408
+ h4
409
+ [
410
+ i
411
+ [
412
+ a
413
+ ~a:
414
+ [
415
+ a_href
416
+ (" ?list_all=" ^ R.Pipeline.Group. id group);
417
+ ]
418
+ [ txt " show inactive pipelines" ];
419
+ ];
420
+ ];
421
+ ]))
359
422
360
423
(* SHOW PIPELINES *)
361
424
let find_pipeline ~(state : t ) pipeline_source_id pipeline_id =
362
425
let src, pipelines =
363
- SourceMap. bindings ! state
426
+ SourceMap. bindings state.runs
364
427
|> List. find (fun (source , _ ) ->
365
428
R.Pipeline.Source. id source = pipeline_source_id)
366
429
in
@@ -442,7 +505,8 @@ module Make (R : Renderer) = struct
442
505
br () ;
443
506
h2 [ txt " History:" ];
444
507
ul
445
- (SourceMap. find src ! state |> StringMap. bindings |> List. rev_map snd
508
+ (SourceMap. find src state.runs
509
+ |> StringMap. bindings |> List. rev_map snd
446
510
|> List. sort
447
511
(fun
448
512
({ metadata = { creation_date = a ; _ } ; _ } :
@@ -683,7 +747,7 @@ module Make (R : Renderer) = struct
683
747
let internal_get_routes ctx ~state =
684
748
Routes.
685
749
[
686
- nil @--> list_pipelines ~state ;
750
+ nil @--> list_pipelines ctx ~state ;
687
751
(str / str /? nil) @--> show_pipeline ctx ~state ;
688
752
(str / str / str /? nil) @--> show_pipeline_task ~state ;
689
753
(str / str / str /? wildcard) @--> show_pipeline_task_job ~state ;
0 commit comments