job runner
This commit is contained in:
parent
80ee0ec3b1
commit
ba9a8eab88
6 changed files with 65 additions and 13 deletions
|
@ -11,15 +11,10 @@ open Pentole.String
|
||||||
open Pentole.Map
|
open Pentole.Map
|
||||||
open Pentole
|
open Pentole
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
type PatternType = After of string
|
type PatternType = After of string
|
||||||
|
|
||||||
|
|
||||||
type WhenExpr = | Cron of Instant | Pattern of PatternType
|
type WhenExpr = | Cron of Instant | Pattern of PatternType
|
||||||
|
|
||||||
|
|
||||||
type CronJobDefinition = {
|
type CronJobDefinition = {
|
||||||
job_name: string
|
job_name: string
|
||||||
user: string
|
user: string
|
||||||
|
@ -42,7 +37,6 @@ let private convert def = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let local_tz = DateTimeZoneProviders.Tzdb.GetSystemDefault ()
|
let local_tz = DateTimeZoneProviders.Tzdb.GetSystemDefault ()
|
||||||
|
|
||||||
let local_tz_net = System.TimeZoneInfo.Local
|
let local_tz_net = System.TimeZoneInfo.Local
|
||||||
|
|
|
@ -8,6 +8,7 @@ open Pentole.Path
|
||||||
[<GenerateSerializer>]
|
[<GenerateSerializer>]
|
||||||
type Notification = | Time | Database
|
type Notification = | Time | Database
|
||||||
|
|
||||||
|
[<GenerateSerializer>]
|
||||||
type CronJob = {
|
type CronJob = {
|
||||||
job_name: string
|
job_name: string
|
||||||
user: string
|
user: string
|
||||||
|
|
|
@ -18,9 +18,14 @@ type ShellGrain() =
|
||||||
|
|
||||||
interface IShellGrain with
|
interface IShellGrain with
|
||||||
member _.schedule (ct) (jobs: ChainOfJobs) = task {
|
member _.schedule (ct) (jobs: ChainOfJobs) = task {
|
||||||
printfn "Grain view: --------"
|
// printfn "Grain view: --------"
|
||||||
printfn "HEAD= %A" jobs.head
|
// printfn "HEAD= %A" jobs.head
|
||||||
jobs.rest |> List.iter (printfn "%A")
|
// jobs.rest |> List.iter (printfn "%A")
|
||||||
printfn "--------"
|
// printfn "--------"
|
||||||
|
let! rc =
|
||||||
|
jobs.head
|
||||||
|
|> Shell.run_job
|
||||||
|
match rc with
|
||||||
|
| Ok rc -> printfn "rc = OK %A" rc
|
||||||
|
| Error rc -> printfn "rc = Error %A" rc
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,11 @@ type Bidello(client: IClusterClient) =
|
||||||
|
|
||||||
let schedule_jobs (jobs: ChainOfJobs) =
|
let schedule_jobs (jobs: ChainOfJobs) =
|
||||||
let runner = rnd.Next () |> client.GetGrain<IShellGrain>
|
let runner = rnd.Next () |> client.GetGrain<IShellGrain>
|
||||||
|
// let rc =
|
||||||
|
// Shell.run_job jobs.head
|
||||||
|
// |> Async.AwaitTask
|
||||||
|
// |> Async.RunSynchronously
|
||||||
|
// printfn "JOB= %A" rc
|
||||||
runner.schedule ct jobs |> ignore
|
runner.schedule ct jobs |> ignore
|
||||||
|
|
||||||
task {
|
task {
|
||||||
|
|
49
src/Shell.fs
49
src/Shell.fs
|
@ -1,10 +1,14 @@
|
||||||
module Bidello.Shell
|
module Bidello.Shell
|
||||||
|
|
||||||
open Sheller
|
|
||||||
|
|
||||||
open FSharp.Control.LazyExtensions
|
open FSharp.Control.LazyExtensions
|
||||||
|
open System.Collections.Generic
|
||||||
|
|
||||||
|
open Sheller
|
||||||
open Pentole.Path
|
open Pentole.Path
|
||||||
|
open Pentole
|
||||||
|
|
||||||
|
open Bidello.Datatypes
|
||||||
|
|
||||||
let private shell_ () =
|
let private shell_ () =
|
||||||
let possible_shells = [
|
let possible_shells = [
|
||||||
|
@ -48,3 +52,46 @@ let which (executable: string) =
|
||||||
|
|
||||||
shell.Value
|
shell.Value
|
||||||
|> Result.bind run
|
|> Result.bind run
|
||||||
|
|
||||||
|
type RunResult =
|
||||||
|
| Success of string | Failure of (int * string)
|
||||||
|
| Unknown of string | NoShell of string
|
||||||
|
|
||||||
|
let run_job (cj: CronJob) = task {
|
||||||
|
|
||||||
|
let workdir = cj.workdir |> function Absolute a -> a + "/"
|
||||||
|
let executable = cj.executable |> function Absolute a -> a
|
||||||
|
let user = cj.user
|
||||||
|
let env =
|
||||||
|
cj.environment
|
||||||
|
|> Seq.map (fun (k, v) -> KeyValuePair (k, v))
|
||||||
|
|
||||||
|
let run (shell: string) = task {
|
||||||
|
try
|
||||||
|
let! rc =
|
||||||
|
Builder
|
||||||
|
.UseShell(shell)
|
||||||
|
.WithEnvironmentVariables(env)
|
||||||
|
.UseExecutable(executable)
|
||||||
|
.WithArgument(Array.ofList cj.args)
|
||||||
|
.UseStartInfoTransform(fun si ->
|
||||||
|
si.WorkingDirectory <- workdir
|
||||||
|
si.UserName <- user
|
||||||
|
)
|
||||||
|
.UseNoThrow()
|
||||||
|
.ExecuteAsync ()
|
||||||
|
|
||||||
|
if rc.ExitCode = 0 then
|
||||||
|
return rc.StandardOutput.Trim () |> Success
|
||||||
|
else
|
||||||
|
return Failure (rc.ExitCode, rc.StandardError)
|
||||||
|
with exn ->
|
||||||
|
return Unknown exn.Message
|
||||||
|
}
|
||||||
|
|
||||||
|
match shell.Value with
|
||||||
|
| Error e -> return NoShell e
|
||||||
|
| Ok shell ->
|
||||||
|
printfn $"Running: {executable}|{shell}|{workdir}|{user}"
|
||||||
|
return! run shell
|
||||||
|
}
|
||||||
|
|
|
@ -13,8 +13,8 @@
|
||||||
<Compile Include="Seq.fs" />
|
<Compile Include="Seq.fs" />
|
||||||
<Compile Include="Result.fs" />
|
<Compile Include="Result.fs" />
|
||||||
<Compile Include="String.fs" />
|
<Compile Include="String.fs" />
|
||||||
<Compile Include="Shell.fs" />
|
|
||||||
<Compile Include="Datatypes.fs" />
|
<Compile Include="Datatypes.fs" />
|
||||||
|
<Compile Include="Shell.fs" />
|
||||||
<Compile Include="Grains.fs" />
|
<Compile Include="Grains.fs" />
|
||||||
<Compile Include="DatabaseMigrations.fs" />
|
<Compile Include="DatabaseMigrations.fs" />
|
||||||
<Compile Include="Database.fs" />
|
<Compile Include="Database.fs" />
|
||||||
|
|
Loading…
Reference in a new issue