Skip to content

Commit f640c34

Browse files
authored
Merge pull request #1108 from terrateamio/978-fix-hanging-status
978 fix hanging status
2 parents 89cb717 + d6119ea commit f640c34

9 files changed

+422
-165
lines changed

code/src/terrat_vcs_event_evaluator2/terrat_vcs_event_evaluator2_tasks.ml

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ struct
282282
Builder.run_db s ~f:(fun db ->
283283
S.Api.create_client ~request_id:(Builder.log_id s) (Builder.State.config s) account db))
284284

285+
let commit_checks = run ~name:"commit_checks" (fun _s _ -> Abb.Future.return (Ok []))
286+
285287
let context_id =
286288
run ~name:"context_id" (fun s { Bs.Fetcher.fetch } ->
287289
let open Irm in
@@ -2446,12 +2448,12 @@ struct
24462448
fetch Keys.work_manifest_event
24472449
>>= function
24482450
| Some event -> (
2449-
let work_manifest =
2451+
let work_manifest, event_type =
2452+
let module E = Keys.Work_manifest_event in
24502453
match event with
2451-
| Keys.Work_manifest_event.(
2452-
( Initiate { work_manifest; _ }
2453-
| Fail { work_manifest; _ }
2454-
| Result { work_manifest; _ } )) -> work_manifest
2454+
| E.Initiate { work_manifest; _ } -> (work_manifest, "INITIATE")
2455+
| E.Fail { work_manifest; _ } -> (work_manifest, "FAIL")
2456+
| E.Result { work_manifest; _ } -> (work_manifest, "RESULT")
24552457
in
24562458
fetch Keys.work_manifest_event_job
24572459
>>= function
@@ -2465,8 +2467,10 @@ struct
24652467
let context = job.Tjc.Job.context in
24662468
Logs.info (fun m ->
24672469
m
2468-
"%s : context_id=%a : log_id= %s : initiator=%s"
2470+
"%s : EVENT : WORK_MANIFEST : %s : context_id=%a : log_id= %s : \
2471+
initiator=%s"
24692472
(Builder.log_id s)
2473+
event_type
24702474
Uuidm.pp
24712475
context.Tjc.Context.id
24722476
log_id
@@ -2494,25 +2498,33 @@ struct
24942498
let iter_job =
24952499
run ~name:"iter_job" (fun s { Bs.Fetcher.fetch } ->
24962500
let open Irm in
2497-
fetch Keys.job
2498-
>>= fun job ->
2499-
match job.Tjc.Job.type_ with
2500-
| Tjc.Job.Type_.Apply _ | Tjc.Job.Type_.Autoapply -> fetch Keys.run_apply
2501-
| Tjc.Job.Type_.Autoplan | Tjc.Job.Type_.Plan _ ->
2502-
fetch Keys.run_plan
2503-
>>= fun () ->
2504-
let s' =
2505-
s
2506-
|> Builder.State.orig_store
2507-
|> Tasks_base.forward_std_keys s
2508-
|> CCFun.flip Builder.State.set_orig_store s
2509-
in
2510-
Builder.eval s' Keys.complete_no_change_dirspaces
2511-
| Tjc.Job.Type_.Repo_config -> fetch Keys.publish_repo_config
2512-
| Tjc.Job.Type_.Unlock _ -> fetch Keys.publish_unlock
2513-
| Tjc.Job.Type_.Index -> fetch Keys.publish_index_complete
2514-
| Tjc.Job.Type_.Push -> fetch Keys.eval_push_event
2515-
| Tjc.Job.Type_.Gate_approval _ -> fetch Keys.store_gate_approval)
2501+
fetch Keys.repo_config_raw'
2502+
>>= fun (_, repo_config) ->
2503+
let module V1 = Terrat_base_repo_config_v1 in
2504+
match V1.enabled repo_config with
2505+
| true -> (
2506+
fetch Keys.job
2507+
>>= fun job ->
2508+
match job.Tjc.Job.type_ with
2509+
| Tjc.Job.Type_.Apply _ | Tjc.Job.Type_.Autoapply -> fetch Keys.run_apply
2510+
| Tjc.Job.Type_.Autoplan | Tjc.Job.Type_.Plan _ ->
2511+
fetch Keys.run_plan
2512+
>>= fun () ->
2513+
let s' =
2514+
s
2515+
|> Builder.State.orig_store
2516+
|> Tasks_base.forward_std_keys s
2517+
|> CCFun.flip Builder.State.set_orig_store s
2518+
in
2519+
Builder.eval s' Keys.complete_no_change_dirspaces
2520+
| Tjc.Job.Type_.Repo_config -> fetch Keys.publish_repo_config
2521+
| Tjc.Job.Type_.Unlock _ -> fetch Keys.publish_unlock
2522+
| Tjc.Job.Type_.Index -> fetch Keys.publish_index_complete
2523+
| Tjc.Job.Type_.Push -> fetch Keys.eval_push_event
2524+
| Tjc.Job.Type_.Gate_approval _ -> fetch Keys.store_gate_approval)
2525+
| false ->
2526+
Logs.info (fun m -> m "%s : DISABLED" (Builder.log_id s));
2527+
Abb.Future.return (Error `Noop))
25162528

25172529
let eval_work_manifest_failure =
25182530
run ~name:"eval_work_manifest_failure" (fun s { Bs.Fetcher.fetch } ->
@@ -3126,6 +3138,7 @@ struct
31263138
|> Hmap.add (coerce Keys.check_account_tier) Tasks.check_account_tier
31273139
|> Hmap.add (coerce Keys.check_valid_destination_branch) Tasks.check_valid_destination_branch
31283140
|> Hmap.add (coerce Keys.client) Tasks.client
3141+
|> Hmap.add (coerce Keys.commit_checks) Tasks.commit_checks
31293142
|> Hmap.add (coerce Keys.complete_no_change_dirspaces) Tasks.complete_no_change_dirspaces
31303143
|> Hmap.add (coerce Keys.compute_node) Tasks.compute_node
31313144
|> Hmap.add (coerce Keys.context) Tasks.context

code/src/terrat_vcs_event_evaluator2/terrat_vcs_event_evaluator2_tasks_pr.ml

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,32 @@ struct
150150
Abb.Future.return
151151
(Ok
152152
(fun branch_ref checks ->
153+
(* When updating commit checks, mark the existing key as dirty. *)
154+
Builder.State.mark_dirty s Keys.commit_checks;
153155
S.Api.create_commit_checks
154156
~request_id:(Builder.log_id s)
155157
client
156158
repo
157159
branch_ref
158160
checks)))
159161

162+
let commit_checks =
163+
run ~name:"commit_checks" (fun s { Bs.Fetcher.fetch } ->
164+
let open Irm in
165+
fetch Keys.client
166+
>>= fun client ->
167+
fetch Keys.repo
168+
>>= fun repo ->
169+
fetch Keys.branch_ref
170+
>>= fun branch_ref ->
171+
Logs.info (fun m ->
172+
m
173+
"%s : FETCH_COMMIT_CHECKS : repo = %s : branch = %s"
174+
(Builder.log_id s)
175+
(S.Api.Repo.to_string repo)
176+
(S.Api.Ref.to_string branch_ref));
177+
S.Api.fetch_commit_checks ~request_id:(Builder.log_id s) client repo branch_ref)
178+
160179
let branch_name =
161180
run ~name:"branch_name" (fun s { Bs.Fetcher.fetch } ->
162181
let open Irm in
@@ -555,24 +574,10 @@ struct
555574
match S.Api.Pull_request.state pull_request with
556575
| Pr.State.Closed ->
557576
Logs.info (fun m -> m "%s : NOOP : PR_CLOSED" (Builder.log_id s));
558-
fetch Keys.client
559-
>>= fun client ->
560-
fetch Keys.repo
561-
>>= fun repo ->
577+
fetch Keys.commit_checks
578+
>>= fun commit_checks ->
562579
fetch Keys.branch_ref
563580
>>= fun branch_ref ->
564-
time_it
565-
s
566-
(fun m log_id time ->
567-
m
568-
"%s : FETCH_COMMIT_CHECKS : repo = %s : branch = %s : time=%f"
569-
log_id
570-
(S.Api.Repo.to_string repo)
571-
(S.Api.Ref.to_string branch_ref)
572-
time)
573-
(fun () ->
574-
S.Api.fetch_commit_checks ~request_id:(Builder.log_id s) client repo branch_ref)
575-
>>= fun commit_checks ->
576581
let module Ch = Terrat_commit_check in
577582
let unfinished_checks =
578583
CCList.filter_map
@@ -1206,8 +1211,10 @@ struct
12061211
>>= fun _ ->
12071212
fetch Keys.store_stacks
12081213
>>= fun () ->
1209-
Abbs_future_combinators.Infix_result_app.(
1210-
(fun () () () () () () () () () () -> ())
1214+
fetch Keys.check_dirspaces_to_plan
1215+
>>= fun () ->
1216+
Fc.Infix_result_app.(
1217+
(fun () () () () () () () () () -> ())
12111218
<$> fetch Keys.check_access_control_ci_change
12121219
<*> fetch Keys.check_access_control_files
12131220
<*> fetch Keys.check_access_control_repo_config
@@ -1216,8 +1223,7 @@ struct
12161223
<*> fetch Keys.check_account_status_expired
12171224
<*> fetch Keys.check_account_tier
12181225
<*> fetch Keys.check_merge_conflict
1219-
<*> fetch Keys.check_conflicting_plan_work_manifests
1220-
<*> fetch Keys.check_dirspaces_to_plan)
1226+
<*> fetch Keys.check_conflicting_plan_work_manifests)
12211227
in
12221228
let open Abb.Future.Infix_monad in
12231229
run
@@ -1255,8 +1261,15 @@ struct
12551261
let open Irm in
12561262
fetch Keys.check_pull_request_state
12571263
>>= fun () ->
1258-
Abbs_future_combinators.Infix_result_app.(
1259-
(fun () () () () () () () () () () () () _ _ _ -> ())
1264+
(* Building these two happens to build all sorts of useful
1265+
dependencies for us, so build those first so the rest can
1266+
efficiently be done concurrently. *)
1267+
Fc.Result.all2 (fetch Keys.branch_dirspaces) (fetch Keys.dest_branch_dirspaces)
1268+
>>= fun _ ->
1269+
fetch Keys.check_dirspaces_to_apply
1270+
>>= fun () ->
1271+
Fc.Infix_result_app.(
1272+
(fun () () () () () () () () () () () _ -> ())
12601273
<$> fetch Keys.check_access_control_ci_change
12611274
<*> fetch Keys.check_access_control_apply
12621275
<*> fetch Keys.check_access_control_files
@@ -1266,13 +1279,9 @@ struct
12661279
<*> fetch Keys.check_conflicting_apply_work_manifests
12671280
<*> fetch Keys.check_dirspaces_missing_plans
12681281
<*> fetch Keys.check_dirspaces_owned_by_other_pull_requests
1269-
<*> fetch Keys.check_dirspaces_to_apply
12701282
<*> fetch Keys.check_gates
12711283
<*> fetch Keys.check_merge_conflict
1272-
<*> fetch Keys.check_apply_requirements
1273-
(* Ensure that various information is built before trying to run the plan *)
1274-
<*> fetch Keys.branch_dirspaces
1275-
<*> fetch Keys.dest_branch_dirspaces)
1284+
<*> fetch Keys.check_apply_requirements)
12761285
in
12771286
let open Abb.Future.Infix_monad in
12781287
run
@@ -1364,7 +1373,8 @@ struct
13641373
let log_id = Builder.mk_log_id ~request_id:(Builder.log_id s) job.Tjc.Job.id in
13651374
Logs.info (fun m ->
13661375
m
1367-
"%s : target=%s : context_id=%a : log_id= %s : job_type=%a"
1376+
"%s : EVENT : PULL_REQUEST : target=%s : context_id=%a : log_id= %s : \
1377+
job_type=%a"
13681378
(Builder.log_id s)
13691379
(Hmap.Key.info Keys.iter_job)
13701380
Uuidm.pp
@@ -1442,6 +1452,7 @@ struct
14421452
|> Hmap.add (coerce Keys.check_merge_conflict) Tasks.check_merge_conflict
14431453
|> Hmap.add (coerce Keys.check_pull_request_state) Tasks.check_pull_request_state
14441454
|> Hmap.add (coerce Keys.comment_id) Tasks.comment_id
1455+
|> Hmap.add (coerce Keys.commit_checks) Tasks.commit_checks
14451456
|> Hmap.add (coerce Keys.create_commit_checks) Tasks.create_commit_checks
14461457
|> Hmap.add (coerce Keys.dest_branch_name) Tasks.dest_branch_name
14471458
|> Hmap.add (coerce Keys.dest_branch_ref) Tasks.dest_branch_ref

0 commit comments

Comments
 (0)