Skip to content

Run Schedules

For class object stacks, explicit job schedules are required. This is an uncommon requirement, but necessary for stacks with many jobs like CI or pipelines divided into groups of jobs.

Example: Docker CI Schedule

def schedule(self):
    # Record commit information
    sched = self.stack.new_sched()
    sched.job = "record_commit"
    sched.archive.timeout = 300
    sched.archive.timewait = 60
    sched.archive.cleanup.instance = "clear"
    sched.failure.keep_resources = True
    sched.conditions.retries = 1
    sched.conditions.frequency = "wait_last_run 20"
    sched.automation_phase = "continuous_delivery"
    sched.human_description = "Insert commit info into run"
    sched.on_success = ["unit_test"]
    self.stack.add_sched(sched)

    # Run unit tests
    sched = self.stack.new_schedule()
    sched.job = "unit_test"
    sched.archive.timeout = 2700
    sched.archive.timewait = 120
    sched.archive.cleanup.instance = "clear"
    sched.failure.keep_resources = True
    sched.conditions.frequency = "wait_last_run 60"

    # Cannot have concurrency with a single docker host
    # The below says another unit_test cannot run
    # while register_docker is running because they run on the
    # same dockerhost. This can change with a more sophisticated
    # stack. This will also prevent a bunch of builds from completing
    # due to race conditions. It's not a big deal because
    # the "runs" don't complete as it waits to stop the server, but
    # the unit_test and register of docker has completed.
    sched.conditions.noncurrent = ["register_docker", "stop_server"]
    sched.automation_phase = "continuous_delivery"
    sched.human_description = "Running unit_test for code"
    sched.on_success = ["register_docker"]
    sched.on_failure = ["stop_server"]
    self.stack.add_sched(sched)

    # Register Docker container
    sched = self.stack.new_sched()
    sched.job = "register_docker"
    sched.archive.timeout = 2700
    sched.archive.timewait = 120
    sched.archive.cleanup.instance = "clear"
    sched.failure.keep_resources = True
    sched.conditions.noncurrent = ["unit_test", "stop_server"]
    sched.conditions.frequency = "wait_last_run 60"
    sched.automation_phase = "continuous_delivery"
    sched.human_description = "Building docker container with code"
    sched.on_success = ["stop_server"]
    sched.on_failure = ["stop_server"]
    self.stack.add_sched(sched)

    # Stop server
    sched = self.stack.new_sched()
    sched.job = "stop_server"
    sched.archive.timeout = 300
    sched.archive.timewait = 10
    sched.archive.cleanup.instance = "clear"
    sched.failure.keep_resources = True
    sched.conditions.noncurrent = ["unit_test", "register_docker"]
    sched.conditions.frequency = "wait_last_run 10"
    sched.automation_phase = "continuous_delivery"
    sched.human_description = "Stopping docker host"
    self.stack.add_sched(sched)

    return self.stack.schedules

Key Methods

  • self.stack.new_sched() - Creates a job schedule object.
  • self.stack.add_sched(sched) - Finalizes a schedule job object, where “sched” is the object.

Basic Usage Pattern

sched = self.stack.new_sched()
# Configure schedule settings...
self.stack.add_sched(sched)