-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #156 from patricoferris/custom-jobs
Support custom jobs
- Loading branch information
Showing
14 changed files
with
248 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
type payload = Raw.Reader.pointer_t | ||
|
||
type 'a t = { | ||
kind : string; | ||
payload : 'a; | ||
} | ||
|
||
type send = (Raw.Builder.pointer_t -> unit) t | ||
type recv = Raw.Reader.pointer_t t | ||
|
||
let v ~kind payload = { kind; payload } | ||
|
||
let kind t = t.kind | ||
let payload t = t.payload | ||
|
||
let read (action : Raw.Reader.Custom.t) = | ||
let payload = Raw.Reader.Custom.payload_get action in | ||
let kind = Raw.Reader.Custom.kind_get action in | ||
{ kind; payload } | ||
|
||
let init b { kind; payload } = | ||
Raw.Builder.Custom.kind_set b kind; | ||
payload (Raw.Builder.Custom.payload_get b) |
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,23 @@ | ||
type payload = Raw.Reader.pointer_t | ||
(** The custom job specification payload. *) | ||
|
||
type 'a t | ||
(** Custom job specifications *) | ||
|
||
type send = (Raw.Builder.pointer_t -> unit) t | ||
type recv = Raw.Reader.pointer_t t | ||
|
||
val v : kind:string -> (Raw.Builder.pointer_t -> unit) -> send | ||
(** [v ~kind payload] is a custom job specification. *) | ||
|
||
val kind : _ t -> string | ||
(** A string describing the kind of custom job. *) | ||
|
||
val payload : 'a t -> 'a | ||
(** The dynamic payload of the custom job. *) | ||
|
||
val init : Raw.Builder.Custom.t -> send -> unit | ||
(** [init builder t] initialises a fresh builder with the values from [t]. *) | ||
|
||
val read : Raw.Reader.Custom.t -> recv | ||
(** [read c] reads the buffer and returns a custom job specification. *) |
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
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,53 @@ | ||
open Lwt.Infix | ||
|
||
module Spec = struct | ||
let obuilder_spec_to_custom spec builder = | ||
let open Cluster_api.Raw in | ||
let obuilder = Builder.OBuilder.init_pointer builder in | ||
Builder.OBuilder.spec_set obuilder spec | ||
|
||
let dockerfile_to_custom spec = | ||
let open Cluster_api.Raw in | ||
let custom = Builder.Custom.init_root () in | ||
let builder = Builder.Custom.payload_get custom in | ||
let df = Builder.DockerBuild.Dockerfile.init_pointer builder in | ||
Builder.DockerBuild.Dockerfile.contents_set df spec; | ||
let r = Reader.Custom.of_builder custom in | ||
Reader.Custom.payload_get r | ||
end | ||
|
||
(* Using the underlying Connection API to submit custom build jobs which are really | ||
just dockerfile builds in disguise. *) | ||
module Build = struct | ||
module Op = struct | ||
type t = Current_ocluster.Connection.t | ||
let ( >>!= ) = Lwt_result.bind | ||
let id = "mock-ocluster-build" | ||
|
||
(* Build Pool *) | ||
module Key = Current.String | ||
(* Dockerfile Spec *) | ||
module Value = Current.String | ||
|
||
module Outcome = Current.String | ||
|
||
let pp = Fmt.(pair string string) | ||
|
||
let auto_cancel = true | ||
let latched = true | ||
|
||
let run t job pool value = | ||
let action = Cluster_api.Submission.custom_build @@ Cluster_api.Custom.v ~kind:"dockerfile" @@ Spec.obuilder_spec_to_custom value in | ||
let build_pool = Current_ocluster.Connection.pool ~job ~pool ~action ~cache_hint:"" t in | ||
Current.Job.start_with ~pool:build_pool job ~level:Current.Level.Average >>= fun build_job -> | ||
Capnp_rpc_lwt.Capability.with_ref build_job (Current_ocluster.Connection.run_job ~job) | ||
end | ||
|
||
module BC = Current_cache.Generic (Op) | ||
|
||
let build_dockerfile t pool spec = | ||
let open Current.Syntax in | ||
Current.component "mock custom cluster build" |> | ||
let> () = Current.return () in | ||
BC.run t pool spec | ||
end |
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
Oops, something went wrong.