Socket
Socket
Sign inDemoInstall

@developedbyant/scheduler

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @developedbyant/scheduler

Simple and fast node js scheduler.


Version published
Maintainers
1
Created

Readme

Source

Simple node.js scheduler

Node.js scheduler using while loop and await

Scheduler takes a prop

interface Props{
    /** Run at given hour and minute */
    runAt:{ hour:0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23,minute:number } | { hour:-1,minute:-1 }
    /** (Milliseconds) run function every given time */
    every:number
    /** Do not run on given week days (1=monday) */
    skipDays?:number[]
    /** Tell function to run passed func first or after wait(every) time */
    runFuncFirst?:boolean
    /** Function to run */
    func:Function
    /** TimeZone */
    TZ?:string
}

Import module

import scheduler from "@developedbyant/scheduler"

Examples of how to use

// Import function
import scheduler from "@developedbyant/scheduler"

// Run every|24hours (1440000)
// At 9:30am and skip saturday and sunday
scheduler({
    runAt:{ hour:9, minute:30 },
    every:1440000,
    skipDays:[6,7],
    func:()=> { 
        console.log("Running function")
    }
})

// Run function right alway every 5 seconds
scheduler({
    // Set { hour:-1, minute:-1 } to run right alway
    runAt:{ hour:-1, minute:-1 },
    // 5 Seconds = 5000 milliseconds
    every:5000,
    // Do not skip any day
    skipDays:[],
    func:()=>{ 
        console.log("Running function")
    }
})

// Run function right alway every 5 seconds
// Set runFuncFirst to run function and wait for prop.every after
scheduler({
    // Set { hour:-1, minute:-1 } to run right alway
    runAt:{ hour:-1, minute:-1 },
    // Set runFuncFirst to run function and wait for prop.every after
    runFuncFirst:true,
    // 5 Seconds = 5000 milliseconds
    every:5000,
    // Do not skip any day
    skipDays:[],
    func:()=>{ 
        console.log("Running function")
    }
})

Keywords

FAQs

Last updated on 24 Oct 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc