Skip to content

Commit

Permalink
utils: new module Toplevel_eval
Browse files Browse the repository at this point in the history
useful for interactive use of bistro
  • Loading branch information
pveber committed Oct 1, 2019
1 parent 7f624d7 commit 42ac2d6
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
53 changes: 53 additions & 0 deletions lib/utils/toplevel_eval.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
open Bistro
open Bistro_engine

module Make(P : sig
val np : int
val mem : int
end)() =
struct
open P

let with_workflow w ~f =
let open Scheduler in
let db = Db.init_exn "_bistro" in
let loggers = [ Console_logger.create () ] in
let sched = create ~np:np ~mem:(`GB mem) ~loggers db in
let thread = eval_exn sched w in
start sched ;
try
Lwt_main.run thread
|> f
with
| Failure msg as e -> (print_endline msg ; raise e)

let eval w = with_workflow w ~f:(fun x -> x)

let with_pworkflow w ~f = with_workflow (Workflow.eval_path w) ~f

let path w =
with_pworkflow w ~f:(fun x -> x)

let sh fmt =
Printf.kprintf (fun s -> ignore (Sys.command s)) fmt

let rm w = with_pworkflow w ~f:(sh "rm %s")

let file w =
with_pworkflow w ~f:(sh "file %s")

let less w =
with_pworkflow w ~f:(sh "less %s")

let wc w =
with_pworkflow w ~f:(sh "wc %s")

let firefox w =
with_pworkflow w ~f:(sh "firefox --no-remote %s")

let evince w =
with_pworkflow w ~f:(sh "evince %s")

let ls w =
with_pworkflow w ~f:(sh "ls %s")
end
13 changes: 13 additions & 0 deletions lib/utils/toplevel_eval.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
open Bistro

module Make(P : sig val np : int val mem : int end)() : sig
val eval : 'a workflow -> 'a
val path : _ pworkflow -> string
val file : _ pworkflow -> unit
val ls : _ pworkflow -> unit
val less : #text_file pworkflow -> unit
val firefox : _ pworkflow -> unit
val evince : pdf pworkflow -> unit
val wc : #text_file pworkflow -> unit
val rm : _ pworkflow -> unit
end

0 comments on commit 42ac2d6

Please sign in to comment.