You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

3.1 KiB

Usage

By adding cron as a service, all other services in auto pair mode, requiring a schedule-command will use it.

cron:

There are no options to set.

schedule-command relation

If most other services will have default options and set these values automatically. You probably don't need to configure anything in the relation's options if defaults suits you.

Although, from the schedule-command relation towards this charm, in your compose.yml, you can explicitly add, replace, or override parameters (if any default was set), and manage replace, add, or fine tune command to be scheduled.

Please remember that commands will be run in cron's container.

Direct value, sequence or struct relations options

You can specify a schedule (required), command (there's a default for run-once services, which is to run the service without any arguments, otherwise you'll need to specify a command), optional lock options, and a label option.

The label option will help separate several commands by naming a lock and naming the log file of the script: $CRON_DATASTORE/var/log/cron/launch-$SERVICE-$label_script.log. If empty or not provided the file name will be: $CRON_DATASTORE/var/log/cron/launch-$SERVICE-$label_script.log.

Please notice that many charm will provide defaults for those values, and you can override any settings.

Direct value for one command
myservice:
  # ...
  relations:
    # ...
    schedule-command:
      cron: !replace  ## could be also !prepend, or !append, note that !replace is default
        #schedule: */5 * * * *
        #command: |
        #  dc run --rm "$SERVICE_NAME" mycommand
        #label:
Sequences or struct for multiple commands

It can be a list of these:

myservice:
  # ...
  relations:
    # ...
    schedule-command:
      cron: !replace  ## could be also !prepend, or !append, note that !replace is default
        - schedule: "*/5 * * * *"
          command: dc run --rm "$SERVICE_NAME" mycommand1
          lock: !append -k
          label: command1
        - schedule: @daily
          command: dc run --rm "$SERVICE_NAME" mycommand
          label: command2

And this is the short form:

myservice:
  # ...
  relations:
    # ...
    schedule-command:
      cron: !replace  ## could be also !prepend, or !append, note that !replace is default.
        command1: (*/5 * * * *) {-k} dc run --rm "$SERVICE_NAME" mycommand1
        command2:
Short syntax or explicit syntax

This is supported in literal, sequence, and struct form:

myservice:
  # ...
  relations:
    # ...
    schedule-command:
      cron: !replace  (*/5 * * * *) {-k} dc run --rm "$SERVICE_NAME" mycommand
myservice:
  # ...
  relations:
    # ...
    schedule-command:
      cron: !prepend
        - labelfoo: */5 * * * * dc run --rm "$SERVICE_NAME" mycommand
myservice:
  # ...
  relations:
    # ...
    schedule-command:
      cron: !prepend
        labelfoo: */5 * * * * dc run --rm "$SERVICE_NAME" mycommand