Light-weight crontab for handling repetitive tasks in React js
npm install --save reactjs-crontab
make sure to add date-fns as dev dependencies since this package depending on date-fns
npm install date-fns@^2.0.0 --save-dev
Now it supports multiple config time values
MIN-HOUR-DOM-MON-DOW-TIMEZONE
OR
Can be multiple values like this
MIN,MIN-HOUR,HOUR-DOM,DOM-MON,MON-DOW,DOW-TIMEZONE
*
means every minute*
means every hour*
means every day*
means every month*
means every dayReactjs-crontab has very similar pattern to Linux Crontab. To learn linux crontab Linux Crontab The difference is that this uses dash between arguments like this *-*-*-*-*-*
. Whereas Linux crontab uses white space like this * * * * * *
import React from 'react'
import { BasicCron } from 'reactjs-crontab'
import 'reactjs-crontab/dist/index.css'
const sayHello = () => {
console.log('Hello')
}
const sayGoobye = () => {
console.log('Goodbye')
}
const RequestSomething = () => {
console.log('Api request has been sent')
}
const sendNotification = () => {
console.log('Send Event Notification')
}
const logUserOut = () => {
console.log('log user out')
}
// these are the functions which will run according to your settings
const tasks = [
// just put this array into BasicCron component as a props and it will work like magic!
{
fn: sayHello,
id: '1',
config: '*-*-*-*-*-utc',
// Execute every minutes
name: 'Say Hello',
description: 'Say Hello on console'
},
{
fn: sayGoobye,
id: '2',
config: '5-7-12-11-*-utc',
// Execute In November on 12th At 7AM and At 5 minute(s)
name: 'Say Goodbye',
description: 'Say Goodbye on console'
},
{
fn: RequestSomething,
id: '3',
config: '*-15,19-*-11,12-*-4',
// Execute In November, December At 3PM, 7PM every minute
name: 'Request Something',
description: 'Send API'
},
{
fn: sendNotification,
id: '4',
config: '10-11-18-7-*-utc',
// Execute In July on 18th At 11AM and At 10 minute(s)
name: 'Send Notification',
description: 'Send Event Notification'
},
{
fn: logUserOut,
id: '5',
config: '*-16-*-10-1-utc',
// Execute In October on Monday At 4PM every minute
name: 'Log user out'
}
]
const App = () => {
// this will display dashboard with scheduled tasks
return <BasicCron tasks={tasks} />
}
export default App
BasicCron Props {
tasks [
{
fn: yourFn, // (required field) type function
id: '1', // (required field) type string
config: '*-11-18-10,13-*-utc', // (required field) type string
name: 'logUserOut', // (optional field) type string
description: 'Send API' // (optional field) type string
}
]
}
Author: shawnscoding
Source Code: https://github.com/shawnscoding/reactjs-crontab
#react #reactjs #javascript