Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jacobbubu/job-list
https://github.com/jacobbubu/job-list
Last synced: 14 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/jacobbubu/job-list
- Owner: jacobbubu
- License: mit
- Created: 2020-08-10T09:11:33.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-09-26T14:39:36.000Z (over 4 years ago)
- Last Synced: 2024-04-29T08:22:07.656Z (9 months ago)
- Language: TypeScript
- Homepage:
- Size: 331 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# @jacobbubu/job-list
[![Build Status](https://github.com/jacobbubu/job-list/workflows/Build%20and%20Release/badge.svg)](https://github.com/jacobbubu/job-list/actions?query=workflow%3A%22Build+and+Release%22)
[![Coverage Status](https://coveralls.io/repos/github/jacobbubu/job-list/badge.svg)](https://coveralls.io/github/jacobbubu/job-list)
[![npm](https://img.shields.io/npm/v/@jacobbubu/job-list.svg)](https://www.npmjs.com/package/@jacobbubu/job-list/)> Implementation of job data structure with [scuttlebutt protocol](https://github.com/jacobbubu/scuttlebutt-pull).
## Intro.
`job-list` is a data structure developed based on the scuttlebutt protocol to express job status and operations.
## Usage
### Sync version
``` ts
import { link } from '@jacobbubu/scuttlebutt-pull'
import { JobList } from '../src'const a = new JobList({ id: 'A' })
const b = new JobList({ id: 'B' })const job = a.create({ id: 'job-1', initial: 'META-1' })
job.progress('STEP-1')
job.progress('STEP-2')
job.extra('EXTRA-1')
job.done(null, 'DONE')
job.extra('EXTRA-2')console.log('job@A:', job.toJSON())
const s1 = a.createStream({ name: 's1' })
const s2 = b.createStream({ name: 's2' })link(s1, s2)
b.on('createdByPeer', (jobId, initial, jobList, update) => {
console.log(`job(${jobId}) created@B`, jobList.getJob(jobId)?.toJSON())
})b.on('progressByPeer', (jobId, progress, jobList, update) => {
console.log(`job(${jobId}) progress:`, progress)
})b.on('extraByPeer', (jobId, progress, jobList, update) => {
console.log(`job(${jobId}) extra:`, progress)
})b.on('doneByPeer', (jobId, err, res, jobList, update) => {
console.log(`job(${jobId}) done:`, [err, res])
})```
### Async version
``` ts
import { link } from '@jacobbubu/scuttlebutt-pull'
import { AsyncJobList, SQLiteStore } from '../src'const main = async () => {
const tableName = 'JobList'const a = new AsyncJobList({
id: 'A',
store: new SQLiteStore({ filename: ':memory:' }, tableName),
})
const b = new AsyncJobList({
id: 'B',
store: new SQLiteStore({ filename: ':memory:' }, tableName),
})const job = await a.create({ id: 'job-A', initial: 'META-1' })
await job.progress('STEP-1')
await job.progress('STEP-2')
await job.extra('EXTRA-1')
await job.done(null, 'DONE!')
await job.extra('EXTRA-2')console.log('job@A:', job.toJSON())
const s1 = a.createStream({ name: 's1' })
const s2 = b.createStream({ name: 's2' })link(s1, s2)
b.on('createdByPeer', async (jobId, initial, jobList, update) => {
console.log(`job(${jobId}) created@B`, (await jobList.getJob(jobId))?.toJSON())
})b.on('progressByPeer', async (jobId, progress, jobList, update) => {
console.log(`job(${jobId}) progress:`, progress)
})b.on('extraByPeer', async (jobId, progress, jobList, update) => {
console.log(`job(${jobId}) extra:`, progress)
})b.on('doneByPeer', async (jobId, err, res, jobList, update) => {
console.log(`job(${jobId}) done:`, [err, res])
})
}// tslint:disable-next-line no-floating-promises
main()
```