text stringlengths 0 601k |
|---|
let report { Exn_with_backtrace . exn ; backtrace } = let exn , memo_stack = match exn with | Memo . Error . E err -> ( Memo . Error . get err , Memo . Error . stack err ) | _ -> ( exn , [ ] ) in match exn with | Already_reported -> ( ) | _ -> let { responsible ; msg ; has_embedded_location ; needs_stack_trace } = get_... |
module Map = Map . Make ( String ) |
let state = ref Map . empty |
let ordered_ids = ref [ ] |
let register_cleaner ( ) = let cleaner ? ctx : _ _ = state := Map . empty ; ordered_ids := [ ] ; Lwt . return ( ) in Sihl . Cleaner . register_cleaner cleaner ; ; |
let register_migration ( ) = ( ) |
let enqueue ? ctx : _ job_instance = let open Sihl . Contract . Queue in let id = job_instance . id in ordered_ids := List . cons id ! ordered_ids ; state := Map . add id job_instance ! state ; Lwt . return ( ) ; ; |
let enqueue_all ? ctx : _ job_instances = job_instances |> List . fold_left ( fun res job -> Lwt . bind res ( fun _ -> enqueue job ) ) ( Lwt . return ( ) ) ; ; |
let update ? ctx : _ job_instance = let open Sihl . Contract . Queue in let id = job_instance . id in state := Map . add id job_instance ! state ; Lwt . return ( ) ; ; |
let find_workable ? ctx : _ ( ) = let all_job_instances = List . map ( fun id -> Map . find_opt id ! state ) ! ordered_ids in let now = Ptime_clock . now ( ) in let rec filter_pending all_job_instances result = match all_job_instances with | Some job_instance :: job_instances -> if Sihl . Contract . Queue . should_run ... |
let query ? ctx : _ ( ) = Lwt . return @@ List . map ( fun id -> Map . find id ! state ) ! ordered_ids ; ; |
let find ? ctx : _ id = Lwt . return @@ Map . find_opt id ! state |
let delete ? ctx : _ ( job : Sihl . Contract . Queue . instance ) = state := Map . remove job . id ! state ; Lwt . return ( ) ; ; |
module Map = Map . Make ( String ) |
let status = let open Sihl . Contract . Queue in let to_string = function | Pending -> " pending " | Succeeded -> " succeeded " | Failed -> " failed " | Cancelled -> " cancelled " in let of_string str = match str with | " pending " -> Ok Pending | " succeeded " -> Ok Succeeded | " failed " -> Ok Failed | " cancelled " ... |
let job = let open Sihl . Contract . Queue in let encode m = Ok ( m . id , ( m . name , ( m . input , ( m . tries , ( m . next_run_at , ( m . max_tries , ( m . status , ( m . last_error , m . last_error_at ) ) ) ) ) ) ) ) in let decode ( id , ( name , ( input , ( tries , ( next_run_at , ( max_tries , ( status , ( last_... |
module MakeMariaDb ( MigrationService : Sihl . Contract . Migration . Sig ) = struct let lifecycles = [ Sihl . Database . lifecycle ; MigrationService . lifecycle ] let enqueue_request = let open Caqti_request . Infix in { sql | INSERT INTO queue_jobs ( uuid , name , input , tries , next_run_at , max_tries , status , l... |
module MakePostgreSql ( MigrationService : Sihl . Contract . Migration . Sig ) = struct let lifecycles = [ Sihl . Database . lifecycle ; MigrationService . lifecycle ] let enqueue_request = let open Caqti_request . Infix in { sql | INSERT INTO queue_jobs ( uuid , name , input , tries , next_run_at , max_tries , status ... |
let t = let open Github in let pp_sep fmt ( ) = Format . fprintf fmt " ; " in let print_yearly_stats stats = Format . printf " Yearly commit activity . . " ; @ List . iter ( fun x -> Format . printf " { days : [ % a ] " ( Format . pp_print_list ~ pp_sep Format . pp_print_int ) x . Github_t . commit_activity_days ; Form... |
type t = | Flat of { header : Int64 . t ; data : Int64 . Hex . t array } | Block of { header : Int64 . t ; data : t array } | Int of Int64 . t |
module M = Mlvalues . Make ( Ops . Int64 ) |
let obj_of_int64 i = let x = Obj . repr Int64 . ( to_int_exn ( shift_right i 1 ) ) in if Int64 . ( i land 1L = 1L ) then x else Obj . add_offset x ( - 1l ) ; ; |
let int64_of_obj o = let bitlo = if Obj . is_int o then 1L else 0L in let valhi = Int64 . of_int ( Obj . magic o : int ) in Int64 . ( shift_left valhi 1 lor bitlo ) ; ; |
let rec of_obj ( ? closure = true ) o = if Obj . is_block o then ( let tag , size = Obj . tag o , Obj . size o in if ( not closure ) && tag = Obj . closure_tag then Int M . val_unit else if tag < Obj . no_scan_tag then Block { header = M . make_header ( Int64 . of_int size ) M . white ( Int64 . of_int tag ) ; data = Ar... |
let rec to_obj r = match r with | Int i -> Obj . repr Int64 . ( to_int_exn ( shift_right i 1 ) ) | Flat { header = h ; data = d } -> let size = Array . length d in let tag = M . tag h in let b = Obj . new_block ( Int64 . to_int_exn tag ) size in for i = 0 to size - 1 do Obj . set_field b i ( obj_of_int64 d . ( i ) ) do... |
let to_data64 data base_word_offset = let is_int = function | Int v -> Some v | _ -> None in let rec size = function | Int _ -> 1 | Flat { data ; _ } -> 1 + Array . length data | Block { data ; _ } -> 1 + Array . fold data ~ init : 0 ~ f ( : fun acc x -> acc + match is_int x with | None -> 1 + size x | _ -> 1 ) in let ... |
let of_data64 ( ? closure = true ) d p = let rec f p = if Int64 . equal ( M . is_block p ) 1L then ( let p ' = Int64 . to_int_exn p / 8 in let header = d . { p ' - 1 } in let tag = M . tag header in let size = M . size header in if ( not closure ) && Int64 . equal tag M . closure_tag then Int M . val_unit else if Int64... |
type error = [ ` Bad_request | ` Bad_gateway | ` Internal_server_error | ` Exn of exn ] |
module Response_state = struct type t = | Waiting | Fixed of Response . t | Streaming of Response . t * Body . Writer . t end |
module Input_state = struct type t = | Ready | Complete end |
module Output_state = struct type t = | Waiting | Ready | Complete end |
type error_handler = ? request : Request . t -> error -> ( Headers . t -> Body . Writer . t ) t -> unit |
module Writer = Serialize . Writer * ; mutable response_body : Response . Body . Writer . t * ; mutable persistent : bool * ; mutable response_state : [ ` Waiting | ` Started | ` Streaming ] * } * ] } * * ) * |
type t = { request : Request . t ; request_body : Body . Reader . t ; writer : Writer . t ; response_body_buffer : Bigstringaf . t ; error_handler : error_handler ; mutable persistent : bool ; mutable response_state : Response_state . t ; mutable error_code : [ ` Ok | error ] } |
let create error_handler request request_body writer response_body_buffer = { request ; request_body ; writer ; response_body_buffer ; error_handler ; persistent = Request . persistent_connection request ; response_state = Waiting ; error_code = ` Ok } |
let request { request ; _ } = request |
let request_body { request_body ; _ } = request_body |
let response { response_state ; _ } = match response_state with | Waiting -> None | Streaming ( response , _ ) _ | Fixed response -> Some response |
let response_exn { response_state ; _ } = match response_state with | Waiting -> failwith " httpaf . Reqd . response_exn : response has not started " | Streaming ( response , _ ) _ | Fixed response -> response |
let respond_with_string t response str = if t . error_code <> ` Ok then failwith " httpaf . Reqd . respond_with_string : invalid state , currently handling error " ; match t . response_state with | Waiting -> Writer . write_response t . writer response ; Writer . write_string t . writer str ; if t . persistent then t .... |
let respond_with_bigstring t response ( bstr : Bigstringaf . t ) t = if t . error_code <> ` Ok then failwith " httpaf . Reqd . respond_with_bigstring : invalid state , currently handling error " ; match t . response_state with | Waiting -> Writer . write_response t . writer response ; Writer . schedule_bigstring t . wr... |
let unsafe_respond_with_streaming ~ flush_headers_immediately t response = match t . response_state with | Waiting -> let encoding = match Response . body_length ~ request_method : t . request . meth response with | ` Fixed _ | ` Close_delimited | ` Chunked as encoding -> encoding | ` Error ( ` Bad_gateway | ` Internal... |
let respond_with_streaming ( ? flush_headers_immediately = false ) false t response = if t . error_code <> ` Ok then failwith " httpaf . Reqd . respond_with_streaming : invalid state , currently handling error " ; unsafe_respond_with_streaming ~ flush_headers_immediately t response |
let report_error t error = t . persistent <- false ; Body . Reader . close t . request_body ; match t . response_state , t . error_code with | Waiting , ` Ok -> t . error_code <- ( error :> [ ` Ok | error ] error ) error ; let status = match ( error :> [ error | Status . standard ] standard ) standard with | ` Exn _ ->... |
let report_exn t exn = report_error t ( ` Exn exn ) exn |
let try_with t f : ( unit , exn ) exn Result . result = try f ( ) ; Ok ( ) with exn -> report_exn t exn ; Error exn |
let close_request_body { request_body ; _ } = Body . Reader . close request_body |
let error_code t = match t . error_code with | # error as error -> Some error | ` Ok -> None |
let persistent_connection t = t . persistent |
let input_state t : Input_state . t = if Body . Reader . is_closed t . request_body then Complete else Ready ; ; |
let output_state t : Output_state . t = match t . response_state with | Fixed _ -> Complete | Streaming ( _ , response_body ) response_body -> if Body . Writer . has_pending_output response_body then Ready else if Body . Writer . is_closed response_body then Complete else Waiting | Waiting -> Waiting ; ; |
let flush_request_body t = if Body . Reader . has_pending_output t . request_body then try Body . Reader . execute_read t . request_body with exn -> report_exn t exn |
let flush_response_body t = match t . response_state with | Streaming ( _ , response_body ) response_body -> Body . Writer . transfer_to_writer response_body t . writer | _ -> ( ) |
let wrap_request mc s = let l = String . length s + 1 in let preamble_mc = String . create 5 in preamble_mc . [ 0 ] <- Char . of_int_exn ( ( l lsr 24 ) land 0xff ) ; preamble_mc . [ 1 ] <- Char . of_int_exn ( ( l lsr 16 ) land 0xff ) ; preamble_mc . [ 2 ] <- Char . of_int_exn ( ( l lsr 8 ) land 0xff ) ; preamble_mc . [... |
let ping ( ) = Ok ( wrap_request ' \ x01 ' " " ) |
let client_id ( ) = Ok ( wrap_request ' \ x03 ' " " ) |
let server_info ( ) = Ok ( wrap_request ' \ x07 ' " " ) |
let bucket_props bucket ( ) = let open Result . Monad_infix in let b = B . create ( ) in B . bytes b 1 bucket >>= fun ( ) -> Ok ( wrap_request ' \ x13 ' ( B . to_string b ) ) |
let list_buckets ( ) = Ok ( wrap_request ' \ x0F ' " " ) |
let list_keys bucket ( ) = let open Result . Monad_infix in let b = B . create ( ) in B . bytes b 1 bucket >>= fun ( ) -> Ok ( wrap_request ' \ x11 ' ( B . to_string b ) ) |
let get g ( ) = let open Opts . Get in let basic_quorum = Option . some_if g . basic_quorum true in let notfound_ok = Option . some_if g . notfound_ok true in let head = Option . some_if g . head true in let deletedvclock = Option . some_if g . deletedvclock true in let open Result . Monad_infix in let b = B . create (... |
let put p ( ) = let open Opts . Put in let content = Robj . Content . to_pb p . content in let return_body = Option . some_if p . return_body true in let if_not_modified = Option . some_if p . if_not_modified true in let if_none_match = Option . some_if p . if_none_match true in let return_head = Option . some_if p . r... |
let delete d ( ) = let open Opts . Delete in let open Result . Monad_infix in let b = B . create ( ) in B . bytes b 1 d . bucket >>= fun ( ) -> B . bytes b 2 d . key >>= fun ( ) -> B . int32_opt b 3 d . rw >>= fun ( ) -> B . bytes_opt b 4 d . vclock >>= fun ( ) -> B . int32_opt b 5 d . r >>= fun ( ) -> B . int32_opt b ... |
let index_search ~ stream idx_s ( ) = let open Opts . Index_search in let determine_index idx_s = match idx_s . query_type with | Query . Eq_int _ | Query . Range_int _ -> | Query . Eq_string _ | Query . Range_string _ -> in let determine_key idx_s = match idx_s . query_type with | Query . Eq_int i -> | Query . Eq_stri... |
module type REQUESTER = sig type t type key type value type param val known : t -> key -> bool Lwt . t type error += Missing_data of key type error += Canceled of key type error += Timeout of key val read : t -> key -> value tzresult Lwt . t val read_opt : t -> key -> value option Lwt . t val fetch : t -> ? peer : P2p_... |
module type FULL_REQUESTER = sig include REQUESTER type store type request_param type notified_value val pending : t -> key -> bool val watch : t -> ( key * value ) Lwt_stream . t * Lwt_watcher . stopper val inject : t -> key -> value -> bool Lwt . t val notify : t -> P2p_peer . Id . t -> key -> notified_value -> unit ... |
module type DISK_TABLE = sig type store type key type value val known : store -> key -> bool Lwt . t val read : store -> key -> value tzresult Lwt . t val read_opt : store -> key -> value option Lwt . t end |
module type MEMORY_TABLE = sig type ' a t type key val create : ? random : bool -> int -> ' a t val find : ' a t -> key -> ' a option val add : ' a t -> key -> ' a -> unit val replace : ' a t -> key -> ' a -> unit val remove : ' a t -> key -> unit val fold : ( key -> ' a -> ' b -> ' b ) -> ' a t -> ' b -> ' b val lengt... |
module type SCHEDULER = sig type t type key type param val request : t -> P2p_peer . Id . t option -> key -> unit val notify : t -> P2p_peer . Id . t -> key -> unit Lwt . t val notify_cancellation : t -> key -> unit val notify_unrequested : t -> P2p_peer . Id . t -> key -> unit Lwt . t val notify_duplicate : t -> P2p_p... |
module type PROBE = sig type key type param type notified_value type value val probe : key -> param -> notified_value -> value option end |
module type REQUEST = sig type key type param val initial_delay : Time . System . Span . t val active : param -> P2p_peer . Set . t val send : param -> P2p_peer . Id . t -> key list -> unit end |
module type HASH = sig type t val name : string val encoding : t Data_encoding . t val pp : Format . formatter -> t -> unit end |
module Make_request_scheduler ( Hash : HASH ) ( Table : MEMORY_TABLE with type key := Hash . t ) ( Request : REQUEST with type key := Hash . t ) : sig include SCHEDULER with type key := Hash . t and type param := Request . param module Events = Requester_event . Make ( Hash ) type key = Hash . t type t = { param : Requ... |
module Make ( Hash : HASH ) ( Disk_table : DISK_TABLE with type key := Hash . t ) ( Memory_table : MEMORY_TABLE with type key := Hash . t ) ( Request : REQUEST with type key := Hash . t ) ( Probe : PROBE with type key := Hash . t and type value := Disk_table . value ) : FULL_REQUESTER with type key = Hash . t and type ... |
let section = [ " node " ; " requester " ; " scheduler " ] |
module Make ( Hash : sig type t val name : string val encoding : t Data_encoding . t struct include Internal_event . Simple let mk_name s = s ^ " __ " ^ Hash . name let notify_push = declare_2 ~ section ~ name ( : mk_name " requester_notify_push " ) ~ msg " : push received { name } from { peer } " ~ level : Debug ( " n... |
module type PARAMETERS = sig type key type value end |
module Disk_memory_table ( P : PARAMETERS ) = struct include Hashtbl . Make ( struct type t = P . key let hash = Hashtbl . hash let equal = ( = ) end ) type store = P . value t type value = P . value let known ( st : store ) ( k : P . key ) = Lwt . return @@ mem st k let read st k = match find st k with Some v -> retur... |
module Memory_table ( P : PARAMETERS ) : Requester . MEMORY_TABLE with type key = P . key = Hashtbl . MakeSeeded ( struct type t = P . key let hash = Hashtbl . seeded_hash let equal = ( = ) end ) |
module Simple_probe ( P : PARAMETERS ) : Requester . PROBE with type key = P . key and type param = bool and type notified_value = P . value and type value = P . value = struct type key = P . key type param = bool type notified_value = P . value type value = P . value let probe ( _ : key ) ( p : param ) ( nv : notified... |
module Simple_request ( P : PARAMETERS ) : sig include Requester . REQUEST with type key = P . key and type param = unit val registered_requests : ( param * P2p_peer . Set . elt * key list ) list ref val clear_registered_requests : unit -> unit type key = P . key type param = unit let initial_delay = Time . System . Sp... |
module Make_memory_full_requester ( H : Requester . HASH ) ( P : PARAMETERS with type key = H . t ) ( R : Requester . REQUEST with type param = unit and type key = H . t ) : Requester . FULL_REQUESTER with type key = H . t and type value = P . value and type param = bool and type request_param = unit and type notified_... |
let module_of_path ~ module_tracker path = match ModuleTracker . ReadOnly . lookup_path module_tracker path with | ModuleTracker . PathLookup . Found { ModulePath . qualifier ; _ } -> Some qualifier | _ -> None |
let instantiate_path ~ build_system ~ ast_environment qualifier = match AstEnvironment . ReadOnly . get_real_path ast_environment qualifier with | None -> None | Some analysis_path -> let path = match BuildSystem . lookup_source build_system analysis_path with | Some source_path -> source_path |> SourcePath . raw | Non... |
let instantiate_error ~ build_system ~ configuration { : Configuration . Analysis . show_error_traces ; _ } ~ ast_environment error = AnalysisError . instantiate ~ show_error_traces ~ lookup ( : instantiate_path ~ build_system ~ ast_environment ) error |
let instantiate_errors ~ build_system ~ configuration ~ ast_environment errors = List . map errors ~ f ( : instantiate_error ~ build_system ~ configuration ~ ast_environment ) |
let process_display_type_error_request ~ configuration ~ state { : ServerState . type_environment ; error_table ; build_system ; _ } paths = let modules = match paths with | [ ] -> Hashtbl . keys error_table | _ -> let get_module_for_source_path path = let path = PyrePath . create_absolute path |> SourcePath . create i... |
let notify_all_subscriptions ~ with_response = function | [ ] -> Lwt . return_unit | _ as subscriptions -> let response = with_response ( ) in List . map subscriptions ~ f ( : fun subscription -> Subscription . send ~ response subscription ) |> Lwt . join |
let create_info_response { ServerProperties . socket_path ; configuration = { Configuration . Analysis . project_root ; local_root ; _ } ; _ ; } = Response . Info { version = Version . version ( ) ; pid = Unix . getpid ( ) |> Pid . to_int ; socket = PyrePath . absolute socket_path ; global_root = PyrePath . show projec... |
let process_incremental_update_request ~ properties ( { : ServerProperties . configuration ; critical_files ; _ } as properties ) ~ state ( { : ServerState . type_environment ; error_table ; subscriptions ; build_system ; _ } as state ) paths = let open Lwt . Infix in let paths = List . map paths ~ f : PyrePath . creat... |
let process_request ~ properties ( { : ServerProperties . configuration ; _ } as properties ) ~ state ( { : ServerState . type_environment ; build_system ; _ } as state ) request = match request with | Request . DisplayTypeError paths -> let response = process_display_type_error_request ~ configuration ~ state paths in... |
module Wrap = struct module type S = sig type max_proofs_verified type max_local_max_proofs_verifieds open Impls . Wrap open Wrap_main_inputs open Snarky_backendless . Request type _ t += | Evals : ( ( Field . Constant . t , Field . Constant . t array ) array Plonk_types . All_evals . t , max_proofs_verified ) Vector .... |
module Step = struct module type S = sig type statement type prev_values type max_proofs_verified type local_signature type local_branches type _ t += | Proof_with_datas : ( prev_values , local_signature , local_branches ) H3 . T ( TPer_proof_witness . Constant ) Constant . t t | Wrap_index : Tock . Curve . Affine . t ... |
let to_http service region req = let uri = Uri . add_query_params ( Uri . of_string ( Aws . Util . of_option_exn ( Endpoints . url_of service region ) ) ) ( List . append [ ( " Version " , [ " 2016 - 11 - 15 " ] ) ; ( " Action " , [ " RequestSpotFleet " ] ) ] ( Util . drop_empty ( Uri . query_of_encoded ( Query . rende... |
let of_http body = try let xml = Ezxmlm . from_string body in let resp = Xml . member " RequestSpotFleetResponse " ( snd xml ) in try Util . or_error ( Util . option_bind resp RequestSpotFleetResponse . parse ) ( let open Error in BadResponse { body ; message = " Could not find well formed RequestSpotFleetResponse . " ... |
let parse_error code err = let errors = [ ] @ Errors_internal . common in match Errors_internal . of_string err with | Some var -> if ( List . mem var errors ) && ( ( match Errors_internal . to_http_code var with | Some var -> var = code | None -> true ) ) then Some var else None | None -> None |
let to_http service region req = let uri = Uri . add_query_params ( Uri . of_string ( Aws . Util . of_option_exn ( Endpoints . url_of service region ) ) ) ( List . append [ ( " Version " , [ " 2016 - 11 - 15 " ] ) ; ( " Action " , [ " RequestSpotInstances " ] ) ] ( Util . drop_empty ( Uri . query_of_encoded ( Query . r... |
let of_http body = try let xml = Ezxmlm . from_string body in let resp = Xml . member " RequestSpotInstancesResponse " ( snd xml ) in try Util . or_error ( Util . option_bind resp RequestSpotInstancesResult . parse ) ( let open Error in BadResponse { body ; message = " Could not find well formed RequestSpotInstancesRes... |
let parse_error code err = let errors = [ ] @ Errors_internal . common in match Errors_internal . of_string err with | Some var -> if ( List . mem var errors ) && ( ( match Errors_internal . to_http_code var with | Some var -> var = code | None -> true ) ) then Some var else None | None -> None |
module Reqd = struct module Body = struct type _ t = { chunks : Bigstringaf . t H . IOVec . t array ; length : int ; mutable index : int ; mutable curr : Bigstringaf . t H . IOVec . t option ; } let schedule_read body ~ on_eof ~ on_read = if body . index = body . length then on_eof ( ) else begin body . curr <- Some bo... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.