Skip to content

Commit 4d96eec

Browse files
committed
Add new option to daemonize: ?no_log_is_ok
The default value is `false` which is the previous behavior and the JSon parsing is backwards compatible thanks to the annotation: `[@default false]`. We still wait for the starting-timeout before checking that condition; this seems that the behavior one would expect.
1 parent f599da6 commit 4d96eec

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

src/lib/ketrew_daemonize.ml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ module Run_parameters = struct
3434
using: [ `Nohup_setsid | `Python_daemon ];
3535
starting_timeout: Time.t;
3636
shell_command: string list;
37+
no_log_is_ok: bool [@default false];
3738
} [@@deriving yojson]
3839

3940
type running = {
@@ -69,10 +70,12 @@ let script_placeholder = "<script>"
6970

7071
let create
7172
?(starting_timeout=5.) ?(call_script=fun s -> [default_shell; s])
72-
?(using=`Nohup_setsid) ?(host=Ketrew_host.tmp_on_localhost) program =
73+
?(using=`Nohup_setsid) ?(host=Ketrew_host.tmp_on_localhost)
74+
?(no_log_is_ok=false)
75+
program =
7376
let shell_command = call_script script_placeholder in
7477
let c =
75-
{host; program; using; starting_timeout; shell_command } in
78+
{host; program; using; starting_timeout; shell_command; no_log_is_ok } in
7679
`Long_running (name, `Created c |> serialize)
7780

7881
let using_to_string = function
@@ -88,6 +91,7 @@ let log =
8891
"Program", Ketrew_program.log c.program;
8992
"Starting-timeout", f c.starting_timeout % s " sec.";
9093
"Call-script", OCaml.list quote c.shell_command;
94+
"No-log-is-OK", OCaml.bool c.no_log_is_ok;
9195
]
9296
| `Running rp -> [
9397
"Status", s "Running" % sp
@@ -314,6 +318,9 @@ let update run_parameters =
314318
| None when elapsed <= run.created.starting_timeout ->
315319
(* no log at all *)
316320
return (`Still_running new_run_parameters)
321+
| None when run.created.no_log_is_ok ->
322+
(* The caller explicitly asked not to care about the log file. *)
323+
return (`Succeeded new_run_parameters)
317324
| None ->
318325
return (`Failed (new_run_parameters, "no log file"))
319326
| Some (`Success date) ->

src/lib/ketrew_daemonize.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ val create:
6262
?starting_timeout:float ->
6363
?call_script:(string -> string list) ->
6464
?using:[ `Nohup_setsid | `Python_daemon] ->
65-
?host:Ketrew_host.t -> Ketrew_program.t ->
65+
?host:Ketrew_host.t -> ?no_log_is_ok: bool -> Ketrew_program.t ->
6666
[> `Long_running of string * string ]
6767
(** Create a “long-running” {!Ketrew_target.build_process} (run parameters
6868
are already serialized), see {!Ketrew_edsl.daemonize} for more

src/lib/ketrew_edsl.mli

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ val daemonize :
239239
?call_script:(string -> string list) ->
240240
?using:[`Nohup_setsid | `Python_daemon] ->
241241
?host:Host.t ->
242+
?no_log_is_ok: bool ->
242243
Program.t ->
243244
Ketrew_target.Build_process.t
244245
(** Create a “daemonize” build process:
@@ -251,6 +252,11 @@ val daemonize :
251252
(default: [(fun script -> ["bash"; script])]).
252253
- [?using]: which method to use when damonizing on the [host]
253254
(see {!Ketrew_daemonize} for more details).
255+
- [?no_log_is_ok]: consider that if the script run does not
256+
produce a log file, the process still has succeeded (the default
257+
and most common is [false], this can be useful for example when
258+
the [Program.t] or [call_script] do something special over the
259+
network).
254260
255261
*)
256262

0 commit comments

Comments
 (0)