rbrahul / deno_cron Goto Github PK
View Code? Open in Web Editor NEWA cron Job scheduler for Deno that allows you to write human readable cron syntax with tons of flexibility
License: MIT License
A cron Job scheduler for Deno that allows you to write human readable cron syntax with tons of flexibility
License: MIT License
Hey,
in the doc you say it starts with seconds but the cron is run every minutes.
deno.json : "cron": "https://deno.land/x/deno_cron/cron.ts",
deno --version:
deno 1.39.1 (release, x86_64-unknown-linux-gnu)
v8 12.0.267.8
typescript 5.3.3
import { cron } from 'cron';
cron('* * * * *', () => {
console.log(new Date()); // every minutes not seconds like documented
});
Thanks for your module.
What about adding timezone? Inspired by https://github.com/kelektiv/node-cron.
Timezone is important because you can execute jobs on machines with a timezone different with respect to the job.
RFC for cron API: cron(schedule, job, timezone)
:
// Run Job at 9a.m. NY time
cron('0 0 9 * * *', () => {
checkStock();
}, "America/New_York"});
export const cron = (schedule: string = '', job: JobType, timezone: string) => {
// I suppose we need to change `schedules` Map, adding timezone info
...
Then in executeJobs
the validation is done for the following date:
schedules.forEach((jobs, schedule, timezone) => {
const date = new Date().toLocaleString("en-US", {timeZone: timezone});
...
What do you think?
I noticed toLocaleString
doesn't work. See denoland/deno#1636
Compare the following snippet in deno
and in node
:
var asiaTime = new Date().toLocaleString("en-US", {timeZone: "Asia/Shanghai"});
console.log('Asia time: '+ (new Date(asiaTime)).toISOString());
If not I would offer to do so.
I am getting this error at intervals. the error seem to come from clearInterval Function on driver.
`Any lead in resolving it permanently? Thanks
at assert (deno:ext/timers/01_timers.js:40:13)
at setGlobalTimeout (deno:ext/timers/01_timers.js:349:5)
at setOrClearGlobalTimeout (deno:ext/timers/01_timers.js:393:7)
at unschedule (deno:ext/timers/01_timers.js:442:9)
at clearTimer (deno:ext/timers/01_timers.js:564:5)
at clearInterval (deno:ext/timers/01_timers.js:581:5)
at https://deno.land/x/[email protected]/cron.ts:118:13
at fire (deno:ext/timers/01_timers.js:477:7)
at handleTimerMacrotask (deno:ext/timers/01_timers.js:338:7)
Watcher Process finished. Restarting on file change...```
hii there,
I have some cronjobs using this that rely on fetch
to get some data from external APIs.
However, sometimes, the internet is offline during the moments these fetches happen.
I cleanly catch these errors like this:
cron('* * * * *', async () => {
try {
await this.update();
} catch(e) {
error(`Could not update Azur Lane server status: ${e.message}`);
}
});
The console shows that it was caught just fine:
[ERR @ 2021/05/20 13:25:05] Could not update Azur Lane server status: error sending request for url (http://blhxusgate.yo-star.com/?cmd=load_server?): error trying to connect: dns error: Device or resource busy (os error 16)
But the cronjob is never run after this again (the only way to fix it, is to re-register the job in the code or restart the Deno process all together).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.