Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shannonmoeller/cronut
Tasty task scheduler with a mungable internal clock filling.
https://github.com/shannonmoeller/cronut
Last synced: 18 days ago
JSON representation
Tasty task scheduler with a mungable internal clock filling.
- Host: GitHub
- URL: https://github.com/shannonmoeller/cronut
- Owner: shannonmoeller
- Created: 2016-10-12T03:04:13.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2016-10-14T13:27:56.000Z (about 8 years ago)
- Last Synced: 2024-10-06T10:42:17.638Z (about 1 month ago)
- Language: JavaScript
- Size: 23.4 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# `cronut`
[![NPM version][npm-img]][npm-url] [![Downloads][downloads-img]][npm-url] [![Build Status][travis-img]][travis-url] [![Coverage Status][coveralls-img]][coveralls-url] [![Tip][amazon-img]][amazon-url]
Tasty task scheduler with a mungable internal clock filling.
## Install
$ npm install --save cronut
## Usage
### Schedule Tasks
```js
import cronut from 'cronut';const cron = cronut();
cron('0 0 0 * * *', () => {
console.log('another hour');
});cron('0 0 * * * *', () => {
console.log('another minute');
});cron('* * * * * *', () => {
console.log('another second');
});cron('0 30 0,12 * * 1-5', () => {
console.log('12:30 AM and PM on weekdays');
});
```### Unschedule Tasks
```js
const removeTask = cron('0 * * * * *', () => {
// only run 10 or so times
console.log('another second');
});// Unschedule after 10 seconds
setTimeout(removeTask, 10000);
```## API
### cronut()
Creates a new task scheduler.
```js
import cronut from 'cronut';const cron = cronut();
```### cron(pattern, task[, options]) : Function
### cron.addTask(pattern, task[, options]) : Function- `pattern` `String`
- `task` `Function`
- `options` `Object`
- `resolution` `Number` Default: `100`.Patterns are any valid pattern supported by [`cron`](http://npm.im/cron). The task is the function to be executed at the appointed times. Returns a function to stop the task.
```js
cron('* * * * * *', () => {
console.log('another second');
});// same as
cron.addTask('* * * * * *', () => {
console.log('another second');
});// removable
const removeTask = cron.addTask('* * * * * *', () => {
console.log('another second');
});removeTask();
```### cron.now(fn)
- `fn` `Function`
Sets the [`moment.now`](http://momentjs.com/docs/#/customization/now/) function and resets internal cron timers.
```js
cron.now(() => {
// It's tomorrow! Heh heh.
return Number(new Date()) + (24 * 60 * 60 * 1000);
});
```## Why?
There are a bunch of task schedulers already available, but none of them allowed me to mess with the internal clock for timeline manipulation or testing purposes.
## Contribute
Standards for this project, including tests, code coverage, and semantics are enforced with a build tool. Pull requests must include passing tests with 100% code coverage and no linting errors.
### Test
$ npm test
----
© Shannon Moeller (http://shannonmoeller.com)
Licensed under [MIT](http://shannonmoeller.com/mit.txt)
[amazon-img]: https://img.shields.io/badge/amazon-tip_jar-yellow.svg?style=flat-square
[amazon-url]: https://www.amazon.com/gp/registry/wishlist/1VQM9ID04YPC5?sort=universal-price
[coveralls-img]: http://img.shields.io/coveralls/shannonmoeller/cronut/master.svg?style=flat-square
[coveralls-url]: https://coveralls.io/r/shannonmoeller/cronut
[downloads-img]: http://img.shields.io/npm/dm/cronut.svg?style=flat-square
[npm-img]: http://img.shields.io/npm/v/cronut.svg?style=flat-square
[npm-url]: https://npmjs.org/package/cronut
[travis-img]: http://img.shields.io/travis/shannonmoeller/cronut/master.svg?style=flat-square
[travis-url]: https://travis-ci.org/shannonmoeller/cronut