add shell

This commit is contained in:
bparodi@lezzo.org 2024-11-16 11:12:01 +01:00
parent 805131c919
commit 05b1aca6be
4 changed files with 51 additions and 8 deletions

View file

@ -1,5 +0,0 @@
module Bidello.Jobs
open Bidello.Datatypes
open NodaTime

View file

@ -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?)
()
}

50
src/Shell.fs Normal file
View file

@ -0,0 +1,50 @@
module Bidello.Shell
open Sheller
open FSharp.Control.LazyExtensions
open Pentole.Path
let private shell_ () =
let possible_shells = [
"/bin/sh"
"/bin/bash"
"/bin/dash"
"/bin/fish"
"/usr/bin/sh"
"/usr/bin/bash"
"/usr/bin/dash"
"/usr/bin/fish"
]
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
let shell = Lazy.Create shell_
let which (executable: string) =
let run (shell: string) =
let rc =
Builder
.UseShell(shell)
.UseExecutable("which")
.WithArgument(executable)
.UseNoThrow()
.ExecuteAsync ()
|> Async.AwaitTask
|> Async.RunSynchronously
if rc.ExitCode = 0 then
rc.StandardOutput
|> _.Trim()
|> Path.of_string
elif rc.ExitCode = 1 then
Error $"Can't find executable path for \"{executable}\"."
else
rc.StandardError
|> Error
shell.Value
|> Result.bind run

View file

@ -13,13 +13,12 @@
<Compile Include="Seq.fs" />
<Compile Include="Result.fs" />
<Compile Include="String.fs" />
<Compile Include="Which.fs" />
<Compile Include="Shell.fs" />
<Compile Include="Datatypes.fs" />
<Compile Include="Grains.fs" />
<Compile Include="DatabaseMigrations.fs" />
<Compile Include="Database.fs" />
<Compile Include="Cron.fs" />
<Compile Include="Jobs.fs" />
<Compile Include="Library.fs" />
</ItemGroup>