Skip to content

Commit e3046ce

Browse files
committed
Add trigger restart as last step, to ensure tree changes picked up immediately
Signed-off-by: Denys Fedoryshchenko <denys.f@collabora.com>
1 parent 709af1c commit e3046ce

File tree

3 files changed

+96
-2
lines changed

3 files changed

+96
-2
lines changed

deployment_manager.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,3 +440,60 @@ async def docker_workaround(self) -> Dict[str, Any]:
440440
)
441441

442442
return {"success": True, "results": results}
443+
444+
async def restart_trigger_service(self) -> Dict[str, Any]:
445+
"""
446+
Restart the trigger service in the pipeline
447+
Returns: {"success": bool, "error": str, "details": dict}
448+
"""
449+
result = {
450+
"success": False,
451+
"error": None,
452+
"details": {"start_time": datetime.utcnow().isoformat()},
453+
}
454+
455+
try:
456+
# Set environment variable for pipeline settings
457+
env = os.environ.copy()
458+
env["SETTINGS"] = PIPELINE_SETTINGS_PATH
459+
460+
# Restart the trigger service using docker-compose
461+
cmd = ["docker-compose"]
462+
463+
# Add compose files if configured
464+
if self.compose_files:
465+
cmd.extend(self.compose_files)
466+
467+
# Add restart command for trigger service
468+
cmd.extend(["restart", "trigger"])
469+
470+
print(f"Restarting trigger service with command: {' '.join(cmd)}")
471+
472+
process = await asyncio.create_subprocess_exec(
473+
*cmd,
474+
stdout=asyncio.subprocess.PIPE,
475+
stderr=asyncio.subprocess.PIPE,
476+
env=env,
477+
cwd=self.pipeline_path,
478+
)
479+
480+
stdout, stderr = await process.communicate()
481+
482+
if process.returncode == 0:
483+
result["success"] = True
484+
result["details"]["stdout"] = stdout.decode("utf-8", errors="ignore")
485+
result["details"]["stderr"] = stderr.decode("utf-8", errors="ignore")
486+
result["details"]["end_time"] = datetime.utcnow().isoformat()
487+
print("Successfully restarted trigger service")
488+
else:
489+
result["error"] = f"Failed to restart trigger service: {stderr.decode('utf-8', errors='ignore')}"
490+
result["details"]["stdout"] = stdout.decode("utf-8", errors="ignore")
491+
result["details"]["stderr"] = stderr.decode("utf-8", errors="ignore")
492+
print(f"Failed to restart trigger service: {result['error']}")
493+
494+
except Exception as e:
495+
result["error"] = f"Exception restarting trigger service: {str(e)}"
496+
result["details"]["exception"] = str(e)
497+
print(f"Exception restarting trigger service: {e}")
498+
499+
return result

models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class StagingStepType(str, enum.Enum):
3232
KERNEL_TREE_UPDATE = "kernel_tree_update"
3333
API_PIPELINE_UPDATE = "api_pipeline_update"
3434
MONITORING_SETUP = "monitoring_setup"
35+
TRIGGER_RESTART = "trigger_restart"
3536

3637

3738
class StagingRunStatus(str, enum.Enum):

orchestrator.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,12 @@ async def initialize_staging_steps(self, staging_run: StagingRun, db: Session):
137137

138138
steps.extend(
139139
[
140-
{"type": StagingStepType.KERNEL_TREE_UPDATE, "order": order_counter},
141140
{
142141
"type": StagingStepType.API_PIPELINE_UPDATE,
143-
"order": order_counter + 1,
142+
"order": order_counter,
144143
},
144+
{"type": StagingStepType.KERNEL_TREE_UPDATE, "order": order_counter + 1},
145+
{"type": StagingStepType.TRIGGER_RESTART, "order": order_counter + 2},
145146
]
146147
)
147148

@@ -221,6 +222,8 @@ async def process_step(
221222
await self.process_kernel_tree_step(staging_run, step, db)
222223
elif step.step_type == StagingStepType.API_PIPELINE_UPDATE:
223224
await self.process_api_pipeline_step(staging_run, step, db)
225+
elif step.step_type == StagingStepType.TRIGGER_RESTART:
226+
await self.process_trigger_restart_step(staging_run, step, db)
224227

225228
async def process_github_workflow_step(
226229
self, staging_run: StagingRun, step: StagingRunStep, db: Session
@@ -441,6 +444,36 @@ async def process_api_pipeline_step(
441444
step.end_time = datetime.utcnow()
442445
db.commit()
443446

447+
async def process_trigger_restart_step(
448+
self, staging_run: StagingRun, step: StagingRunStep, db: Session
449+
):
450+
"""Process trigger restart step - restart the trigger service in pipeline"""
451+
if step.status == StagingStepStatus.PENDING:
452+
step.status = StagingStepStatus.RUNNING
453+
step.start_time = datetime.utcnow()
454+
staging_run.current_step = "trigger_restart"
455+
db.commit()
456+
457+
try:
458+
# Restart the trigger service in the pipeline
459+
result = await self.deployment_manager.restart_trigger_service()
460+
461+
step.end_time = datetime.utcnow()
462+
if result["success"]:
463+
step.status = StagingStepStatus.COMPLETED
464+
step.details = json.dumps(result)
465+
else:
466+
step.status = StagingStepStatus.FAILED
467+
step.error_message = result.get("error", "Unknown error")
468+
469+
db.commit()
470+
471+
except Exception as e:
472+
step.status = StagingStepStatus.FAILED
473+
step.error_message = str(e)
474+
step.end_time = datetime.utcnow()
475+
db.commit()
476+
444477
async def complete_staging_run(
445478
self, staging_run: StagingRun, db: Session, success: bool
446479
):
@@ -508,6 +541,8 @@ async def recover_stuck_steps(self, staging_run: StagingRun, db: Session):
508541
timeout_minutes = 15 # Git operations
509542
elif step.step_type == StagingStepType.SELF_UPDATE:
510543
timeout_minutes = 10 # Quick git pull
544+
elif step.step_type == StagingStepType.TRIGGER_RESTART:
545+
timeout_minutes = 5 # Quick docker restart
511546

512547
if running_duration.total_seconds() > (timeout_minutes * 60):
513548
print(
@@ -576,6 +611,7 @@ async def startup_recovery(self):
576611
StagingStepType.API_PIPELINE_UPDATE,
577612
StagingStepType.KERNEL_TREE_UPDATE,
578613
StagingStepType.SELF_UPDATE,
614+
StagingStepType.TRIGGER_RESTART,
579615
]:
580616
print(
581617
f"Recovering stuck local step: {step.step_type.value}"

0 commit comments

Comments
 (0)