Giter Club home page Giter Club logo

ministryofjustice.cron-formula's Introduction

cron-formula

This formula creates cron setup and jobs from pillar data

Pillar example

cron:                                     # Main cron section
  jobs:                                  # A dictionary of cron jobs
    job1:                               # the job id
      name: helloworld                 # the command to be run
      disabled: False                  # (optional) True to disable the job, default is False
      minute: 1                        # (optional) The information to be set into the minute section. Default is */30
      hour: 2                          # (optional) The information to be set in the hour section. Default is *
      dayweek: 3                       # (optional) The information to be set in the day of week section. Default is *
      daymonth:                        # (optional) The information to be set in the day of month section. Default is *
      user: john                       # (optional) The name of the user whose crontab needs to be modified, defaults to the root user
      random_delay: 0                  # (optional) set a max random delay before running the job
      one_instance: False              # (optional) True will ensure that only one instance runs the job
      comment: "This is my job!"       # (optional) User comment to be added on line previous the cron job
      log: "/var/log/helloworld.log"   # (optional) The file to log the command output to, defaults to cron.log

Syntax idiosyncrasies

Obviously shell scripts can have a very special syntax with special characters and so on. Sometimes you can get errors like:

ParserError: while parsing a block mapping
  in "<unicode string>", line 22, column 7:
        - name: ' /usr/bin/python /srv/sal ...
                ^
expected <block end>, but found '<scalar>'
  in "<unicode string>", line 22, column 94:

Below is a complex example with some such special characters. This was done with the help of http://stackoverflow.com/questions/3790454/in-yaml-how-do-i-break-a-string-over-multiple-lines

process_foo_queue:                               # the job id
  name: |-
    docker exec my_container bash -c ''RAILS_ENV=production bundle exec rake foo:process_queue''
  disabled: False                  # (optional) True to disable the job, default is False
  minute: '*'                        # (optional) The information to be set into the minute section. Default is */30
  one_instance: True               # (optional) True will ensure that only one instance runs the job
  log: "/var/log/schedule.log"

So what is happening here is that the we enter the command in "name:" using |- to indicate a multiline string that does not have any newlines. The double quotation mark results to a single quotation mark. The minute: * may indicate an anchor reference, if so enclose in single quotes. Finally, although not used here, it is worth mentioning that the characters \ and " must be escaped by \ .

ministryofjustice.cron-formula's People

Contributors

ezman avatar filipposc5 avatar sevenmachines avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.