procman 0.23.8

A process supervisor with a dependency DAG and a typed .pman language
config {
  log_time = true
}

arg port {
  type = string
  default = "8080"
  short = "p"
  description = "Port for the web server"
}

# One-shot job: runs to completion before services start.
job migrate {
  run """
    echo "Running migrations..."
    sleep 1
    echo "DATABASE_URL=postgres://localhost/mydb" > $PROCMAN_OUTPUT
    echo "Migrations complete."
  """
}

# Long-running service: starts after migrate finishes AND only once
# `migrate` has emitted the "Migrations complete." line on its output.
# `output_matches` matches a literal substring per output line, so this
# is robust against colorized logs (ANSI is stripped before matching).
service web {
  env PORT = args.port
  env DB_URL = @migrate.DATABASE_URL

  wait {
    after @migrate
    output_matches @migrate "Migrations complete."
  }

  run "echo \"Serving on port $PORT with db $DB_URL\" && sleep 10"
}

# On-demand task: only runs when triggered with -t test_suite.
task test_suite {
  wait {
    after @migrate
  }

  for thing in ["test1", "test2", "test3"] {
    env THING = thing
    run """
      echo "Running test $THING..."
      sleep 1
      echo "Test passed."
    """
  }
}

# On-demand task: only runs when triggered with -t test_suite.
task test_suite_2 {
  wait {
    after @migrate
  }

  run """
    echo "Running test suite 2..."
    sleep 1
    echo "All tests passed."
  """
}