Skip to content

Commit

Permalink
feat: Add availability.exit_on_skipped
Browse files Browse the repository at this point in the history
  • Loading branch information
shivaraj-bh authored and F1bonacc1 committed Aug 16, 2024
1 parent 14b33bc commit e3d9281
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/app/project_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ func (p *ProjectRunner) runProcess(config *types.ProcessConfig) {
log.Error().Msgf("Error: %s", err.Error())
log.Error().Msgf("Error: process %s won't run", proc.getName())
proc.wontRun()
p.onProcessSkipped(proc.procConf)
} else {
exitCode := proc.run()
p.onProcessEnd(exitCode, proc.procConf)
Expand Down Expand Up @@ -186,6 +187,13 @@ func (p *ProjectRunner) onProcessEnd(exitCode int, procConf *types.ProcessConfig
}
}

func (p *ProjectRunner) onProcessSkipped(procConf *types.ProcessConfig) {
if procConf.RestartPolicy.ExitOnSkipped {
p.ShutDownProject()
p.exitCode = 1
}
}

func (p *ProjectRunner) initProcessStates() {
p.statesMutex.Lock()
defer p.statesMutex.Unlock()
Expand Down
1 change: 1 addition & 0 deletions src/types/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ type RestartPolicyConfig struct {
BackoffSeconds int `yaml:"backoff_seconds,omitempty"`
MaxRestarts int `yaml:"max_restarts,omitempty"`
ExitOnEnd bool `yaml:"exit_on_end,omitempty"`
ExitOnSkipped bool `yaml:"exit_on_skipped,omitempty"`
}

type ShutDownParams struct {
Expand Down
25 changes: 25 additions & 0 deletions www/docs/launcher.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,28 @@ processes:

> :bulb:
> `exit_on_end` can be set on more than one process, for example when running multiple tasks in parallel and wishing to terminate as soon as any one finished.

## Terminate Process Compose once given process is skipped

This can be achieved by setting `availability.exit_on_skipped` to `true`. If defined, `process-compose` will gracefully shut down all the other running processes and exit with exit-code `1`.

Here's an example, where `process1` depends on `process2` and `process2` fails:

```yaml hl_lines="10"
processes:
process1:
command: "echo 'Hi from Process1'"
depends_on:
process2:
condition: process_completed_successfully
availability:
# NOTE: `restart: exit_on_failure` is not needed since
# exit_on_skipped implies it.
exit_on_skipped: true
process2:
command: "echo 'Hi from Process2'; exit 1"
process3:
command: "while true; do echo 'Running...'; sleep 1; done"
```
Why can't the same be achieved with `exit_on_end` on `process2`? Yes, it can be, but in a case where `process1` depends on multiple processes, and failure of any of them should cause termination, `exit_on_skipped` can be used to avoid setting `exit_on_end` on all of them.

0 comments on commit e3d9281

Please sign in to comment.