Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mikesparr/redis-task-scheduler
Simple Promise based task scheduler that works with redis-docker-taskrunner
https://github.com/mikesparr/redis-task-scheduler
Last synced: about 6 hours ago
JSON representation
Simple Promise based task scheduler that works with redis-docker-taskrunner
- Host: GitHub
- URL: https://github.com/mikesparr/redis-task-scheduler
- Owner: mikesparr
- License: mit
- Created: 2018-05-24T17:51:02.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-03-24T05:18:19.000Z (almost 6 years ago)
- Last Synced: 2024-12-21T19:02:31.905Z (20 days ago)
- Language: TypeScript
- Size: 83 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Redis Task Scheduler
This module schedules tasks that will be run
with https://github.com/mikesparr/redis-docker-taskrunner# Requirements
Redis must be installed and running, or accessible via network.# Install
```bash
npm install redis-task-scheduler
yarn add redis-task-scheduler
```# Test
Tests are in `src/__tests__` and `src/lib/__tests__` respectively. The app is built in
Typescript but compiles to `.js` files.```bash
npm test
npm run coverage # optional
```# Usage
## Quick start (node)
```javascript
const redis = require("redis");
const rts = require("redis-task-scheduler");const client = redis.createClient();
const scheduler = new rts.RedisTaskScheduler(null, client);// create a job
const testTask = new rts.Task(rts.TaskType.PubSub, "myPubSubChannel", {foo: "bar"});
const testJob = new rts.Job(
`job-${Date.now()}`, // id
testTask, // task
null, // lastRun
5, // interval in minutes
3, // recurrences
0, // runCount
);// schedule it
scheduler.schedule(rts.TaskChannel.Default, testJob)
.then(() => {
console.log("Job scheduled!");
})
.catch((error) => {
console.error("Error: ", error);
});
```## Typescript
```typescript
import * as redis from "redis";
import {
IJob,
IRun,
ITask,
ITaskScheduler,
Job,
RedisTaskScheduler,
Run,
Task,
TaskChannel,
TaskType,
} from "redis-task-scheduler";const client: redis.RedisClient = redis.createClient();
const scheduler: ITaskScheduler = new RedisTaskScheduler(null, client);// create a job
const testTask: ITask = new Task(TaskType.PubSub, "myPubSubChannel", {foo: "bar"});
const testJob: IJob = new Job(
`job-${Date.now()}`, // id
testTask, // task
null, // lastRun
5, // interval in minutes
3, // recurrences
0, // runCount
);// schedule it
scheduler.schedule(TaskChannel.Default, testJob)
.then(() => {
console.log("Job scheduled!");
})
.catch((error) => {
console.error("Error: ", error);
});
```# Contributing
I haven't thought that far ahead. I needed this for my own project and decided to give back.# License
MIT