All Articles

FetchqCRON

Planning time-based jobs

Photo by Curtis MacNewton on Unsplash

Run smart CRON jobs

I started to work on the FetchqCRON project when I realized I was re-implementing the architecture around repeatable jobs over and over, project by project.

And you don’t like to repeat yourself, right?

Let’s start with an example:
An ideal scenario to handle users signup would be:

  1. sign the user up
  2. 👉 in 2 hours, check on the user to see if he/she confirmed his/her email
  3. thank the user

Point n.1 and n.3 are up to your route handler, FetchqCRON lets you solve point n.2 with a simple REST call that plans the execution of a webhook in 2 hours.

You can easily configure how to execute the webhook. It can be any kind of REST call where you are in control of headers and body structure, or it can be a GraphQL query or mutation.

Wanna dig into the documentation?
👉 https://cron.fetchq.com

How to se tup a Webhook job:

Here is an example call that sets up a task with 2 hours delay. It will post to a given URL, providing custom headers:

/* post://fetchq-cron-instance.com/api/v1/cron */

{
  "group_name": "verify-email",
  "task_name": "user123",
  "schedule": {
    "method": "delay",
    "value": "+2 hours"
    },
  "action": {
    "method": "webhook",
    "request": {
      "type": "rest",
      "method": "POST",
      "url": "http://my-web-app.com/webhooks/verify-email/user123".
      "headers": {
        "content-type": "application/json",
        "authorization": "Bearer xxx"
      }
    }
  }
}

The target webhook should respond with statusCode=200 in order to yield a successful run. In such a case, the webhook will be triggered again in 2 more hours.

Successfull webhook execution:
statusCode = 200

In case any error should happen, the action is re-attempted for a configurable amount of times before the system gives up, every failing run is duly logged for full traceability.

Webhooks can reschedule the job:

The target webhook can interact back with the scheduler, providing active feedback and re-programming the execution plan:

/* webhook's response: */
{
  "success": true,
  "schedule": {
    "method": "delay",
    "value": "+999y",
  },
  "logs": [{
    "message": "user email was successfully confirmed"
  }]
}

This kind of response will re-schedule the next execution 999 years in the future. It’s just a hacky way to kill the task. We have more features coming up soon. 😊

It also writes a log entry in the task’s history. FetchqCRON keeps a detailed execution log where you can trace any activity that happened to a task.

Main Features:

  • setup time-based jobs via RESTful API
  • setup time-based jobs via WebConsole
  • access detailed logs per task / group / server
  • scale up the job workers for parallel execution
  • run the server in API only mode (good for micro-service architecture)
  • fine-grained authorization via JWT (*)

(*) in development

Job Types:

  • webhook
  • AWS Lambda functions (*)
  • Docker functions (*)

(*) in development

Try it out on Heroku

😎 Wanna try it?
It takes just a few minutes to run your own instance in Heroku:

deploy on Heroku

🤓 Feeling adventurous?
We have you covered, click here to run the cloud-based development environment:

Open in GitPod

Feedback & Contribute

Read the Documentation:
📖 https://cron.fetchq.com

Please come and give your feedback on our ProductHunt page:
👉 https://www.producthunt.com/posts/fetchq-cron

And don’t forget to give us a star on GitHub:
https://github.com/marcopeg/fetchq-cron