# @buckless/offline-queue

> Simple job queue, mostly used for offline apps

Latest version **1.0.4** (published 2018-12-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install @buckless/offline-queue
pnpm add @buckless/offline-queue
yarn add @buckless/offline-queue
bun add @buckless/offline-queue
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2018-12-12 |
| First published | 2018-04-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 114 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Gabriel Juchault |
| Maintainers | buckless |

## Links

- npm: https://www.npmjs.com/package/@buckless/offline-queue
- Repository: https://github.com/buckless/offline-queue
- Homepage: https://github.com/buckless/offline-queue#readme
- Issues: https://github.com/buckless/offline-queue/issues
- npm.io page: https://npm.io/package/@buckless/offline-queue

## Dependencies (1)

- [eventemitter3](https://npm.io/package/eventemitter3.md) ^3.1.0

## Recent versions

- 1.0.4 (latest) — 2018-12-12
- 1.0.3 — 2018-08-10
- 1.0.2 — 2018-07-20
- 1.0.1 — 2018-07-19
- 1.0.0 — 2018-07-18
- 0.5.1 — 2018-06-09
- 0.5.0 — 2018-05-21
- 0.4.1 — 2018-05-21
- 0.4.0 — 2018-05-21
- 0.3.1 — 2018-05-21
- 0.3.0 — 2018-05-21
- 0.2.0 — 2018-05-21
- 0.1.1 — 2018-05-21
- 0.1.0 — 2018-04-14

## README

# offline-queue

Simple job queue, mostly used for offline apps.

Failing jobs will be pushed to the queue again.

## Usage

```js
const Queue = require('@buckless/offline-queue')

const queue = new Queue({
  // your main queue processor
  process(job) {
    return axios[job.data.method || 'get'](
      job.data.url,
      job.data.body,
      Object.assign({}, authHeaders, job.data.params)
    )
  },

  interval: 60 * 1000 * 1000,
  storage: localStorage
})

queue.on('process', (job, res) => {
  // do something with res (result from your process call)
  console.log(`${job.data.method} on ${job.data.url} succeeded`)
})

queue.on('error', (err, job) => {
  console.error(`${job.data.method} on ${job.data.url} failed because of ${err.message}`)
})

queue
  .push({
    data: {
      method: 'post',
      url: '/some/endpoint',
      data: { foo: 'bar' },
      params: { headers: {} }
    },

    // set to true if you want the job to get executed immediately (it will resolve or reject naturally).
    // if it fails, it will be pushed to the queue
    immediate: someBoolean,

    // a value or a promise that will be resolved (if the job is not immediate, or if the immediate job failed)
    mock: {
      data: {
        value: 12
      }
    }
  })
  .then((res) => {

  })
```

## API

### Type definitions

**Job**

```
{
  data: Object,
  immediate: Boolean,
  mock: Any|Promise<Any>
}
```

**Options**

```
{
  process: (job: Job) -> Promise,
  autostart: Boolean,
  interval: Number,
  storage: Storage
}
```

### Events

```
synchronizing(queue: Jobs[])
```

```
synchronized(queue: Jobs[])
```

```
process(job: Job, data: Any)
```

```
processed(job: Job, data: Any)
```

```
error(job: Job, error: Error)
```

### Methods

```
constructor(opts: Options) -> Queue
```

```
push(job: Job) -> Promise
```

```
sync() -> Promise
```

```
stop() -> void
```

```
# internal
loadFromStorage() -> Promise
```

```
# internal
writeToStorage() -> Promise
```

---
_Source: https://npm.io/package/@buckless/offline-queue · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
