Skip to content

Commit 806fbd0

Browse files
committed
fix: handle run time executions
BB-10516
1 parent a4e9ab7 commit 806fbd0

File tree

3 files changed

+99
-68
lines changed

3 files changed

+99
-68
lines changed

app/core/webhook_actions.py

Lines changed: 90 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
get_workflow_run_summary,
3535
get_argocd_run_summary,
3636
get_max_sandboxes_summary,
37+
get_generic_error_summary,
3738
)
3839
from app.helpers.utils import merge_dicts
3940
from app.models.request_models import PullRequest, WorkflowRun
@@ -43,6 +44,19 @@
4344
logger = logging.getLogger(__name__)
4445

4546

47+
def _post_generic_error_message(check_run: CheckRun, db_session: DBSession) -> None:
48+
summary = get_generic_error_summary()
49+
checkrun_status = CheckRunStatus.COMPLETE
50+
checkrun_conclusion = CheckRunStatus.FAILURE
51+
update_checkrun(
52+
check_run,
53+
summary,
54+
db_session,
55+
status=checkrun_status,
56+
conclusion=checkrun_conclusion,
57+
)
58+
59+
4660
def _sandbox_audit_log(
4761
pull_request: PullRequest, sandbox_status: SandboxStatus, db_session: DBSession
4862
) -> None:
@@ -166,32 +180,36 @@ def create_or_update_instance(
166180
db_session=db_session,
167181
)
168182

169-
sandbox = Sandbox(pull_request.sandbox_name)
170-
171-
# Don't trigger any workflow if create instance workflow is already running
172-
if not sandbox.create_workflow_is_running():
173-
# If sandbox already exists update it, or create a new one
174-
if sandbox.exists:
175-
# Cancel any existing workflow runs for this sandbox first to avoid merge conflicts
176-
sandbox.cancel_any_existing_runs(db_session)
177-
_update_instance(pull_request, sandbox)
178-
elif is_max_instances_exceeded():
179-
logger.info(
180-
"Sandbox %s cannot be created since max sandbox count exceeded",
181-
sandbox.sandbox_name,
182-
)
183-
summary = get_max_sandboxes_summary()
184-
checkrun_status = CheckRunStatus.COMPLETE
185-
checkrun_conclusion = CheckRunStatus.FAILURE
186-
update_checkrun(
187-
check_run,
188-
summary,
189-
db_session,
190-
status=checkrun_status,
191-
conclusion=checkrun_conclusion,
192-
)
193-
else:
194-
_create_new_instance(pull_request, sandbox, db_session)
183+
try:
184+
sandbox = Sandbox(pull_request.sandbox_name)
185+
186+
# Don't trigger any workflow if create instance workflow is already running
187+
if not sandbox.create_workflow_is_running():
188+
# If sandbox already exists update it, or create a new one
189+
if sandbox.exists:
190+
# Cancel any existing workflow runs for this sandbox first to avoid merge conflicts
191+
sandbox.cancel_any_existing_runs(db_session)
192+
_update_instance(pull_request, sandbox)
193+
elif is_max_instances_exceeded():
194+
logger.info(
195+
"Sandbox %s cannot be created since max sandbox count exceeded",
196+
sandbox.sandbox_name,
197+
)
198+
summary = get_max_sandboxes_summary()
199+
checkrun_status = CheckRunStatus.COMPLETE
200+
checkrun_conclusion = CheckRunStatus.FAILURE
201+
update_checkrun(
202+
check_run,
203+
summary,
204+
db_session,
205+
status=checkrun_status,
206+
conclusion=checkrun_conclusion,
207+
)
208+
else:
209+
_create_new_instance(pull_request, sandbox, db_session)
210+
except Exception as e:
211+
_post_generic_error_message(check_run, db_session)
212+
raise e
195213

196214

197215
def delete_instance(
@@ -338,30 +356,49 @@ def handle_workflow_run(
338356
)
339357
return
340358

341-
if github_action == GithubActionTypes.IN_PROGRESS:
342-
post_checkrun_updates(
343-
check_run, sandbox, workflow_run, workflow_type, db_session
344-
)
345-
return
359+
try:
360+
if github_action == GithubActionTypes.IN_PROGRESS:
361+
post_checkrun_updates(
362+
check_run, sandbox, workflow_run, workflow_type, db_session
363+
)
364+
return
365+
366+
if workflow_run.conclusion in WORKFLOW_SUCCESS_CONCLUSION:
367+
trigger_next_workflow(workflow_type, check_run, sandbox, db_session)
368+
post_checkrun_updates(
369+
check_run,
370+
sandbox,
371+
workflow_run,
372+
workflow_type,
373+
db_session,
374+
in_progress=False,
375+
)
376+
elif workflow_run.conclusion == WorkFlowConclusion.CANCELLED:
377+
# Check if the workflow run cancellation was triggered
378+
# intentionally by this app. If so, ignore it. If not,
379+
# then update checkrun as failed.
380+
try:
381+
query = select(CancelledRun).where(
382+
CancelledRun.run_id == workflow_run.id
383+
)
384+
db_session.fetch_one(query)
385+
except DBOperationException:
386+
post_checkrun_updates(
387+
check_run,
388+
sandbox,
389+
workflow_run,
390+
workflow_type,
391+
db_session,
392+
in_progress=False,
393+
failed=True,
394+
)
395+
else:
396+
rerun = False
397+
# Handle failed workflow runs
398+
if workflow_run.attempt < config.max_run_attempt:
399+
rerun = True
400+
sandbox.trigger_workflow_rerun(workflow_run.id, workflow_run.rerun_url)
346401

347-
if workflow_run.conclusion in WORKFLOW_SUCCESS_CONCLUSION:
348-
trigger_next_workflow(workflow_type, check_run, sandbox, db_session)
349-
post_checkrun_updates(
350-
check_run,
351-
sandbox,
352-
workflow_run,
353-
workflow_type,
354-
db_session,
355-
in_progress=False,
356-
)
357-
elif workflow_run.conclusion == WorkFlowConclusion.CANCELLED:
358-
# Check if the workflow run cancellation was triggered
359-
# intentionally by this app. If so, ignore it. If not,
360-
# then update checkrun as failed.
361-
try:
362-
query = select(CancelledRun).where(CancelledRun.run_id == workflow_run.id)
363-
db_session.fetch_one(query)
364-
except DBOperationException:
365402
post_checkrun_updates(
366403
check_run,
367404
sandbox,
@@ -370,24 +407,11 @@ def handle_workflow_run(
370407
db_session,
371408
in_progress=False,
372409
failed=True,
410+
rerun=rerun,
373411
)
374-
else:
375-
rerun = False
376-
# Handle failed workflow runs
377-
if workflow_run.attempt < config.max_run_attempt:
378-
rerun = True
379-
sandbox.trigger_workflow_rerun(workflow_run.id, workflow_run.rerun_url)
380-
381-
post_checkrun_updates(
382-
check_run,
383-
sandbox,
384-
workflow_run,
385-
workflow_type,
386-
db_session,
387-
in_progress=False,
388-
failed=True,
389-
rerun=rerun,
390-
)
412+
except Exception as e:
413+
_post_generic_error_message(check_run, db_session)
414+
raise e
391415

392416

393417
def handle_argocd(

app/helpers/constants.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@
6666
NAMED_RELEASE_MASTER: [
6767
"pip install tutor-contrib-drydock",
6868
# "git+https://github.com/overhangio/tutor.git@main",
69-
"pip install git+https://gitlab.com/opencraft/dev/tutor-contrib-grove@main",
69+
"pip install git+https://gitlab.com/opencraft/dev/tutor-contrib-grove@kaustav/fix_phd_compatibility",
7070
"pip install git+https://github.com/overhangio/tutor-mfe.git@main",
7171
"pip install git+https://github.com/overhangio/tutor-forum.git@main",
7272
# "pip install git+https://gitlab.com/opencraft/dev/tutor-contrib-grove.git@main",
7373
# "pip install git+https://github.com/hastexo/tutor-contrib-s3.git@main",
7474
# "pip install git+https://github.com/openedx/openedx-k8s-harmony.git@main#egg=tutor-contrib-harmony&subdirectory=tutor-contrib-harmony-plugin",
75-
"tutor plugins enable drydock mfe forum grove-mfes grove-phd",
75+
"tutor plugins enable drydock mfe forum grove-mfes grove-config",
7676
# "tutor plugins enable grove-simple-theme",
7777
# "tutor plugins enable grove",
7878
# "tutor plugins enable k8s_harmony",

app/helpers/messages.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,10 @@ def get_max_sandboxes_summary() -> str:
172172
Generate summary for sandbox cancelled due to max sandboxes
173173
"""
174174
return "\n\n### 🚫 Sandbox deployment has been cancelled since the maximum number of sandboxes are already deployed"
175+
176+
177+
def get_generic_error_summary() -> str:
178+
"""
179+
Generate summary for generic error during sandbox deployment
180+
"""
181+
return "\n\n### 🚫 Sandbox deployment failed due to an Internal Server Error. Please retry the deployment and if the issue persistes, please contact [#grove-pr-watcher](https://openedx.slack.com/archives/C05519HHZKM) slack channel."

0 commit comments

Comments
 (0)