F1bonacc1 / process-compose

Process Compose is a simple and flexible scheduler and orchestrator to manage non-containerized applications.
https://f1bonacc1.github.io/process-compose/
Apache License 2.0
1.33k stars 52 forks source link

Process B fails quickly results in "process A depends on B, but it isn't running" #274

Closed secobarbital closed 1 week ago

secobarbital commented 2 weeks ago

Defect

When process A depends on B completing successfully, process A runs if B fails quickly. It should not run if B fails, regardless how quickly.

Version of process-compose: v1.34.0

OS environment: MacOS 14.7.1

Steps or code to reproduce the issue:

process-compose.json:

{
  "processes": {
    "bundle-install": { "command": "sleep 10", "namespace": "default" },
    "configure": { "command": "diff a b", "namespace": "default" },
    "mysql": {
      "availability": { "max_restarts": 5, "restart": "on_failure" },
      "command": "sleep 100",
      "namespace": "mysql.mysql",
      "readiness_probe": {
        "exec": {
          "command": "echo mysql"
        },
        "failure_threshold": 5,
        "initial_delay_seconds": 2,
        "period_seconds": 10,
        "success_threshold": 1,
        "timeout_seconds": 4
      }
    },
    "mysql-configure": {
      "command": "sleep 3",
      "depends_on": { "mysql": { "condition": "process_healthy" } },
      "namespace": "mysql.mysql"
    },
    "prepare-db": {
      "command": "echo PREPARE DB",
      "depends_on": {
        "bundle-install": { "condition": "process_completed_successfully" },
        "configure": { "condition": "process_completed_successfully" },
        "mysql-configure": { "condition": "process_completed_successfully" }
      },
      "namespace": "default"
    },
    "web": {
      "command": "sleep 100",
      "depends_on": {
        "bundle-install": { "condition": "process_completed_successfully" },
        "configure": { "condition": "process_completed_successfully" },
        "prepare-db": { "condition": "process_completed_successfully" }
      },
      "namespace": "default"
    }
  },
  "shell": { "shell_argument": "-c", "shell_command": "/bin/bash" }
}

Expected result:

24-11-07 16:04:39.275 ERR Error: process prepare-db depended on configure to complete successfully, but it exited with status 2
24-11-07 16:04:39.275 ERR Error: process prepare-db won't run

Actual result:

24-11-07 16:04:49.281 ERR Error: process web depends on configure, but it isn't running
24-11-07 16:04:49.281 ERR Error: process web depends on prepare-db, but it isn't running
24-11-07 16:04:49.286 INF Started command=["/bin/bash","-c","sleep 100"] process=web

Full log:

This run had both the good case and the bad case happening:

24-11-07 16:04:39.260 INF Process Compose v1.34.0
24-11-07 16:04:39.261 INF Loaded project from nix/process-compose-enterprise.json
24-11-07 16:04:39.261 INF Global shell command: /bin/bash -c
24-11-07 16:04:39.261 INF start http server listening :8080
24-11-07 16:04:39.261 DBG Spinning up 6 processes. Order: ["configure" "mysql" "mysql-configure" "bundle-install" "prepare-db" "web"]
24-11-07 16:04:39.261 INF web is waiting for bundle-install to complete successfully
24-11-07 16:04:39.262 INF mysql-configure is waiting for mysql to be healthy
24-11-07 16:04:39.262 INF prepare-db is waiting for configure to complete successfully
24-11-07 16:04:39.264 INF Started command=["/bin/bash","-c","sleep 100"] process=mysql
24-11-07 16:04:39.264 INF Started command=["/bin/bash","-c","sleep 10"] process=bundle-install
24-11-07 16:04:39.265 INF Started command=["/bin/bash","-c","diff a b"] process=configure
24-11-07 16:04:39.275 INF Exited exit_code=2 process=configure
24-11-07 16:04:39.275 ERR Error: process prepare-db depended on configure to complete successfully, but it exited with status 2
24-11-07 16:04:39.275 ERR Error: process prepare-db won't run
24-11-07 16:04:41.264 DBG mysql_ready_probe started monitoring
24-11-07 16:04:41.275 INF Started command=["/bin/bash","-c","sleep 3"] process=mysql-configure
24-11-07 16:04:44.288 INF Exited exit_code=0 process=mysql-configure
24-11-07 16:04:49.281 INF Exited exit_code=0 process=bundle-install
24-11-07 16:04:49.281 ERR Error: process web depends on configure, but it isn't running
24-11-07 16:04:49.281 ERR Error: process web depends on prepare-db, but it isn't running
24-11-07 16:04:49.286 INF Started command=["/bin/bash","-c","sleep 100"] process=web
24-11-07 16:06:19.279 INF Exited exit_code=0 process=mysql
24-11-07 16:06:29.315 INF Exited exit_code=0 process=web
24-11-07 16:06:29.315 INF Project completed
24-11-07 16:06:31.008 DBG Shutting down 0 processes. Order: []
24-11-07 16:06:32.009 DBG Logs monitoring canceled
24-11-07 16:06:32.011 DBG TUI Wait stopped
24-11-07 16:06:32.011 INF Thank you for using process-compose
secobarbital commented 2 weeks ago

It looks like waitIfNeeded only looks for the depended on processes in the list of running processes, from which processes are removed once they exit. It should probably check a list of completed processes as well.

F1bonacc1 commented 1 week ago

Thanks for the quick fix @secobarbital. Added in v1.40.0