-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bistro_app.simple: simplified workflow execution
Provides a function for the common case where we want to run a workflow and put some of the targets in given locations. The function wraps the creation of a database and a scheduler, as well as concurrency aspects. This function is defined in the new Bistro_app module, itself inside the new bistro.utils library.
- Loading branch information
Showing
5 changed files
with
87 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
open Core.Std | ||
open Bistro.Std | ||
open Bistro_engine | ||
open Lwt | ||
|
||
type target = string list * Bistro.Workflow.u | ||
|
||
let ( %> ) path w = path, Bistro.Workflow.u w | ||
|
||
let rec string_of_path = function | ||
| [] -> "." | ||
| "" :: t -> Filename.concat "." (string_of_path t) | ||
| p -> List.reduce_exn p ~f:Filename.concat | ||
|
||
let make_absolute p = | ||
if Filename.is_absolute p then p | ||
else Filename.concat (Sys.getcwd ()) p | ||
|
||
let link p p_u = | ||
let dst = string_of_path p in | ||
let src = make_absolute p_u in | ||
Unix.mkdir_p (Filename.dirname dst) ; | ||
let cmd = sprintf "rm -rf %s && ln -s %s %s" dst src dst in | ||
ignore (Sys.command cmd) | ||
|
||
let foreach_target db scheduler (dest, u) = | ||
Scheduler.build' scheduler u >|= function | ||
| `Ok cache_path -> | ||
link dest cache_path ; | ||
`Ok () | ||
| `Error xs -> | ||
`Error ( | ||
List.map xs ~f:(fun (u, msg) -> | ||
Bistro.Workflow.id' u, | ||
msg, | ||
Db.report db u | ||
) | ||
) | ||
|
||
let error_report = function | ||
| `Ok () -> () | ||
| `Error xs -> | ||
List.iter xs ~f:(fun (_,_,report) -> | ||
prerr_endline report | ||
) | ||
|
||
let simple ?(np = 1) ?(mem = 1024) targets = | ||
let db = Db.init_exn "_bistro" in | ||
let scheduler = Scheduler.make ~np ~mem db in | ||
let results = | ||
Lwt_list.map_p (foreach_target db scheduler) targets | ||
|> Lwt_unix.run | ||
in | ||
List.iter results ~f:error_report |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
open Bistro.Std | ||
|
||
type target | ||
|
||
val ( %> ) : string list -> _ workflow -> target | ||
|
||
val simple : | ||
?np:int -> | ||
?mem:int -> | ||
target list -> unit |