Skip to content

Easy to maintain multiple cron job, and auto send job execute log.

License

Notifications You must be signed in to change notification settings

ciao-chung/cron-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cron Service

Easy to maintain multiple cron job, and auto send job execute log.

Feature

  • Allow multiple cron job
  • Allow multiple notify drivers(email, line)

Dependencies

Installation

Clone project

yarn global add cron-service

Start service

base

cron-service --config=/file-to-your/config.json

or pm2

pm2 start cron-service --name="cron" -- --config=/file-to-your/config.json

Configuration

Main

  • jobs: Setup cron job.
  • notifyDrivers: Setup notify driver (configuration see below).

job item

  • name(required): String, name of job item.
  • runAtStart(optional): Boolean, job will run after service launch if this property is true (default value is false).
  • schedule(required): String/Array, schedule rule like cron job(to setup multi schedule you can pass array value), see more rule in cron.
  • commands(required): Array, CommandItem array (CommandItem configuration see below).
  • notify(optional): Array, setup drivers which you wanna notify.
{
  "someCronJob": {
    "name": "Some Cron Job",
    "runAtStart": true,
    "schedule": "*/60 * * * * *",
    "commands": [
      CommandItem,
      CommandItem,
      CommandItem,
    ],
    "notify": ["line", "email"]
  }
}

CommandItem

  • command: Command which you wanna execute.
  • description(required): String, this description will display in execute notify content.
  • cwd(optional): String, Path where command to execute.
{
  "command": "git clone https://foobar.com.git; cd foobar",
  "description": "Clone some repo.",
  "cwd": "/home/project/"
}

Example

{
  "jobs": {
    "someCronJob": {
      "name": "Some Cron Job",
      "runAtStart": true,
      "schedule": "*/60 * * * * *",
      "commands": [
        {
          "command": "rm -rf foobar",
          "description": "remove folder"
        },
        {
          "command": "git clone git@github.com:rtyley/small-test-repo.git foobar; pwd; ls",
          "description": "clone project"
        },
        {
          "command": "cd foobar; ls",
          "description": "go into project"
        },
        {
          "command": "rm -rf foobar",
          "description": "delete project"
        }
      ],
      "notify": ["line", "email"]
    }
  },
  "notifyDrivers": {
    "line": {
      "token": "lineApiToken"
    },
    "email": {
      "transporter": {
        "port": 587,
        "host": "smtp.gmail.com",
        "username": "foo@bar.com",
        "password": "password"
      },
      "send": {
        "from": "foo@bar.com",
        "to": "target1@foobar.com,target2@foobar.com"
      }
    }
  }
}

Notify Drivers

Email

  • transporter: Object, mail configuration.
  • send:
    • from: String, from mail.
    • to: String, one or more receiver.
{
  "notifyDrivers": {
    "email": {
      "transporter": {
        "port": 587,
        "host": "smtp.gmail.com",
        "username": "foo@bar.com",
        "password": "password"
      },
      "send": {
        "from": "foo@bar.com",
        "to": "target1@foobar.com,target2@foobar.com"
      }
    }
  }
}

Line

Line is a popular chat application in asia which like WhatsApp in west countries.

To create access token see offical documentation

  • token: String, access token of line notify api.
{
  "notifyDrivers": {
    "line": {
      "token": "lineApiToken"
    }
  }
}

About

Easy to maintain multiple cron job, and auto send job execute log.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published