# redis-task-scheduler

> Simple Promise based task scheduler using Redis that works with redis-docker-taskrunner

Latest version **0.2.5** (published 2019-03-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install redis-task-scheduler
pnpm add redis-task-scheduler
yarn add redis-task-scheduler
bun add redis-task-scheduler
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.5 |
| Published | 2019-03-24 |
| First published | 2018-05-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 49.6 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Mike Sparr |
| Maintainers | mikesparr |
| Keywords | task, scheduler, cron, workflow, delayed, events, Redis |

## Links

- npm: https://www.npmjs.com/package/redis-task-scheduler
- Repository: https://github.com/mikesparr/redis-task-scheduler
- Homepage: https://github.com/mikesparr/redis-task-scheduler#readme
- Issues: https://github.com/mikesparr/redis-task-scheduler/issues
- npm.io page: https://npm.io/package/redis-task-scheduler

## Dependencies (2)

- [redis](https://npm.io/package/redis.md) ^2.8.0
- [@types/redis](https://npm.io/package/@types/redis.md) ^2.8.6

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 0.2.5 (latest) — 2019-03-24
- 0.2.4 — 2019-03-24
- 0.2.3 — 2019-03-24
- 0.2.2 — 2019-03-24
- 0.2.1 — 2018-11-29
- 0.2.0 — 2018-11-29
- 0.1.4 — 2018-05-26
- 0.1.3 — 2018-05-26
- 0.1.2 — 2018-05-25
- 0.1.1 — 2018-05-24
- 0.1.0 — 2018-05-24

## 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

---
_Source: https://npm.io/package/redis-task-scheduler · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
