Readiness and Wait For

Workloads in a sandbox all start at the same time without a predefined order. However, some automation scripts in the start sequence may need to access other workloads — for example, to initialize a database. Crafting provides a Wait For mechanism at multiple levels to coordinate workload startup.

Workload-Level Wait For

A wait_for list can be added to the definition of a workspace or container workload to declare that it should wait for specific other workloads to be ready before proceeding:

workspaces:
- name: dev
  wait_for:
  - mysql
containers:
- name: sqlpad
  wait_for:
  - mysql
dependencies:
- name: mysql
  service_type: mysql

With this definition:

CLI Wait Command

For more precise control, the cs wait command can be used inside setup scripts or hook scripts to wait for a specific workload at a particular point in the sequence. This avoids unnecessarily blocking earlier steps that do not need the workload to be ready.

workspaces:
- name: dev
  checkouts:
  - path: src
    repo:
      git: git@github.com:example-org/example
    manifest:
      overlays:
      - inline:
          hooks:
            build:
              cmd: |
                ./build.sh
                cs wait service mysql
                ./seed-db.sh
dependencies:
- name: mysql
  service_type: mysql

In this example, ./build.sh runs first (it does not need MySQL and may take a long time). The wait for MySQL only happens after the build is complete, just before ./seed-db.sh which requires the database to be ready.

Readiness

A workload is considered Ready when all of the following conditions are met:

See Also