Source file s.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
(** The subset of the Current API that the RPC system needs.
    This is duplicated here to avoid making RPC clients depend on
    the "current" service implementation package. *)

(** Active pipeline state. *)
type active = [ `Ready | `Running | `Waiting_for_confirmation ]

(** Pipeline output type. *)
type 'a output = ('a, [`Active of active | `Msg of string]) result

(** Pipeline statistics (re-exported from current_term). *)
type stats = Current_term.S.stats = {
  ok : int;
  waiting_for_confirmation : int;
  ready : int;
  running : int;
  failed : int;
  blocked : int;
}

module type CURRENT = sig
  (** The term type representing pipeline computations. *)
  type 'a term

  class type actions = object
    method pp : Format.formatter -> unit
    method rebuild : (unit -> string) option
  end

  module Job : sig
    type t
    module Map : Map.S with type key = string
    val log_path : string -> (Fpath.t, [`Msg of string]) result
    val lookup_running : string -> t option
    val wait_for_log_data : t -> unit Lwt.t
    val approve_early_start : t -> unit
    val cancel : t -> string -> unit
    val cancelled_state : t -> (unit, [`Msg of string]) result
  end

  (** Confirmation levels for operations. *)
  module Level : sig
    type t

    val values : t list
    (** All possible levels, in order. *)

    val to_string : t -> string
    val of_string : string -> (t, [> `Msg of string]) result
  end

  (** Engine configuration. *)
  module Config : sig
    type t

    val get_confirm : t -> Level.t option
    (** Get the current confirmation threshold, if any. *)

    val set_confirm : t -> Level.t option -> unit
    (** Set the confirmation threshold. [None] means no confirmation required. *)
  end

  (** Pipeline metadata for jobs. *)
  module Metadata : sig
    type t = {
      job_id : string option;
      update : active option;
    }
  end

  (** Pipeline analysis module. *)
  module Analysis : sig
    val stat : 'a term -> stats
    (** [stat t] returns statistics about the pipeline states. *)

    val pp_dot :
      env:(string * string) list ->
      collapse_link:(k:string -> v:string -> string option) ->
      job_info:(Metadata.t -> active option * string option) ->
      Format.formatter -> 'a term -> unit
    (** [pp_dot ~env ~collapse_link ~job_info ppf t] outputs the pipeline as a DOT graph. *)
  end

  module Engine : sig
    type t

    type results = {
      value : unit output;
      jobs : actions Job.Map.t;
    }

    val state : t -> results
    val config : t -> Config.t
    (** Get the engine configuration. *)

    val pipeline : t -> unit term
    (** [pipeline t] returns the current pipeline term. *)
  end
end

(** Database operations interface. This matches Current_cache.Db exactly
    so applications can use it directly. *)
module type DB = sig
  type entry = {
    job_id : string;
    build : int64;
    value : string;
    outcome : (string, [`Msg of string]) result;
    ready : float;
    running : float option;
    finished : float;
    rebuild : bool;
  }

  val query :
    ?op:string ->
    ?ok:bool ->
    ?rebuild:bool ->
    ?job_prefix:string ->
    unit -> entry list
  (** Query job history with optional filters. *)

  val ops : unit -> string list
  (** List all known operation types. *)
end

(** A stub DB implementation that returns empty results.
    @deprecated No longer used since Impl uses Current_cache.Db directly. *)
module Db_stub : DB = struct
  type entry = {
    job_id : string;
    build : int64;
    value : string;
    outcome : (string, [`Msg of string]) result;
    ready : float;
    running : float option;
    finished : float;
    rebuild : bool;
  }

  let query ?op:_ ?ok:_ ?rebuild:_ ?job_prefix:_ () = []
  let ops () = []
end