Lenra Docs
Register on Lenra
  • Home
  • Getting started
    Open/Close
  • Guides
    Open/Close
  • Features
    Open/Close
  • References
    Open/Close
  • Contribute

    Crons

    Crons on Lenra are a way to schedule tasks to be executed at specific times. A cron can be managed using the CRUD operations.

    Creating a cron that runs each minute

    To create a cron on Lenra, make a POST request to the /app-api/v1/crons endpoint with the following required parameters:

    The schedule parameter consists of five fields, each separated by a space, that represent minute, hour, day of the month, month, and day of the week. Here is the format:

    * * * * *
    - - - - -
    | | | | |
    | | | | +----- day of the week (0 - 6) (Sunday=0)
    | | | +------- month (1 - 12)
    | | +--------- day of the month (1 - 31)
    | +----------- hour (0 - 23)
    +------------- min (0 - 59)
    

    Each field can take the following values:

    You can also pass props to the request body for additional data that will be sent to the listener, for example:

    {
      "listener_name": "myListener",
      "schedule": "* * * * *",
      "props": {
        "userId": "1234"
      }
    }
    

    The response will contain the created cron with the additional generated name parameter:

    {
      "name": "5c18337c4de4a4a60ce4a6ee",
      "listener_name": "myListener",
      "schedule": "* * * * *",
      "props": {
        "userId": "1234"
      }
    }
    

    You will need to remember this name to properly call the UPDATE and DELETE endpoints that are under /crons/:name.