Skip to content

Commit fa6a2e9

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 fa6a2e9

File tree

3 files changed

+100
-1
lines changed

3 files changed

+100
-1
lines changed

deployment_manager.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,3 +440,62 @@ 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"] = (
490+
f"Failed to restart trigger service: {stderr.decode('utf-8', errors='ignore')}"
491+
)
492+
result["details"]["stdout"] = stdout.decode("utf-8", errors="ignore")
493+
result["details"]["stderr"] = stderr.decode("utf-8", errors="ignore")
494+
print(f"Failed to restart trigger service: {result['error']}")
495+
496+
except Exception as e:
497+
result["error"] = f"Exception restarting trigger service: {str(e)}"
498+
result["details"]["exception"] = str(e)
499+
print(f"Exception restarting trigger service: {e}")
500+
501+
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: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,15 @@ 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,
142+
"order": order_counter,
143+
},
144+
{
145+
"type": StagingStepType.KERNEL_TREE_UPDATE,
143146
"order": order_counter + 1,
144147
},
148+
{"type": StagingStepType.TRIGGER_RESTART, "order": order_counter + 2},
145149
]
146150
)
147151

@@ -221,6 +225,8 @@ async def process_step(
221225
await self.process_kernel_tree_step(staging_run, step, db)
222226
elif step.step_type == StagingStepType.API_PIPELINE_UPDATE:
223227
await self.process_api_pipeline_step(staging_run, step, db)
228+
elif step.step_type == StagingStepType.TRIGGER_RESTART:
229+
await self.process_trigger_restart_step(staging_run, step, db)
224230

225231
async def process_github_workflow_step(
226232
self, staging_run: StagingRun, step: StagingRunStep, db: Session
@@ -441,6 +447,36 @@ async def process_api_pipeline_step(
441447
step.end_time = datetime.utcnow()
442448
db.commit()
443449

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

512550
if running_duration.total_seconds() > (timeout_minutes * 60):
513551
print(
@@ -576,6 +614,7 @@ async def startup_recovery(self):
576614
StagingStepType.API_PIPELINE_UPDATE,
577615
StagingStepType.KERNEL_TREE_UPDATE,
578616
StagingStepType.SELF_UPDATE,
617+
StagingStepType.TRIGGER_RESTART,
579618
]:
580619
print(
581620
f"Recovering stuck local step: {step.step_type.value}"

0 commit comments

Comments
 (0)