From 80ee0ec3b166776adb26a1e8feaad4bd8aea4371 Mon Sep 17 00:00:00 2001 From: "bparodi@lezzo.org" Date: Sat, 16 Nov 2024 11:12:01 +0100 Subject: [PATCH] add shell shell --- src/Cron.fs | 2 +- src/Jobs.fs | 5 ----- src/Library.fs | 1 - src/{Which.fs => Shell.fs} | 24 +++++++++++++++++------- src/src.fsproj | 3 +-- 5 files changed, 19 insertions(+), 16 deletions(-) delete mode 100644 src/Jobs.fs rename src/{Which.fs => Shell.fs} (65%) diff --git a/src/Cron.fs b/src/Cron.fs index 8be832b..d2e1a2b 100644 --- a/src/Cron.fs +++ b/src/Cron.fs @@ -84,7 +84,7 @@ let private parse now (db: Requirements) = else Ok (splitted.[0], splitted.[1])) - let executable = Which.which db.executable + let executable = Shell.which db.executable let workdir = Path.of_string db.workdir |> Result.bind FileSystem.resolve Result.zip when_ env diff --git a/src/Jobs.fs b/src/Jobs.fs deleted file mode 100644 index 86bc152..0000000 --- a/src/Jobs.fs +++ /dev/null @@ -1,5 +0,0 @@ -module Bidello.Jobs - -open Bidello.Datatypes - -open NodaTime diff --git a/src/Library.fs b/src/Library.fs index c63f833..f48fa40 100644 --- a/src/Library.fs +++ b/src/Library.fs @@ -70,7 +70,6 @@ type Bidello(client: IClusterClient) = let timeout = next_job_at - now |> _.TotalMilliseconds |> floor |> int32 // printfn $"Waking up in: {timeout}|{next_job_at}" let! _wake_up = db |> Database.wait_notification timeout ct - // TODO: se il lavoro da fare, è già in esecuzione (e ancora non terminato, che fare?) () } diff --git a/src/Which.fs b/src/Shell.fs similarity index 65% rename from src/Which.fs rename to src/Shell.fs index 3975db5..9b8970e 100644 --- a/src/Which.fs +++ b/src/Shell.fs @@ -1,9 +1,12 @@ -module Bidello.Which +module Bidello.Shell open Sheller + +open FSharp.Control.LazyExtensions + open Pentole.Path -let which (executable: string) = +let private shell_ () = let possible_shells = [ "/bin/sh" "/bin/bash" @@ -15,12 +18,18 @@ let which (executable: string) = "/usr/bin/fish" ] - let shell = List.tryFind (fun sh -> sh |> Path.of_string |> Result.isOk) possible_shells + let error = Error "Can't find the system shell. Check your system $PATH." + List.tryFind (fun sh -> sh |> Path.of_string |> Result.isOk) possible_shells + |> Option.map Ok |> Option.defaultValue error - if shell |> Option.isSome then + +let shell = Lazy.Create shell_ + +let which (executable: string) = + let run (shell: string) = let rc = Builder - .UseShell(shell.Value) + .UseShell(shell) .UseExecutable("which") .WithArgument(executable) .UseNoThrow() @@ -36,5 +45,6 @@ let which (executable: string) = else rc.StandardError |> Error - else - Error "Can't find the system shell. Check your system $PATH." + + shell.Value + |> Result.bind run diff --git a/src/src.fsproj b/src/src.fsproj index 081c662..03e87d2 100644 --- a/src/src.fsproj +++ b/src/src.fsproj @@ -13,13 +13,12 @@ - + -