1.4.10 • Published 1 year ago
electric-flow v1.4.10
Installation
$ npm install electric-flow
required bull and arena ui for bull queue.
Quick start
const ElectricFlow = require('electric-flow')
const electricFlow = new ElectricFlow({
mongoUrl: 'mongodb://localhost:27017/electric-flow',
redisUrl: 'redis://localhost:6379',
statsRedisUrl: 'redis://localhost:6379/1',
enableSlack: true,
slack: {
webhookUrl: 'https://hooks.slack.com/services/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9',
channel: 'testbot',
username: 'Electric-bot'
}
})
const mainboard = new ElectricFlow.MainBoard({})
electricFlow.register(mainboard)
// init all mainboard connection
electricFlow.start()
The settings
fields are:
mongoUrl
: string, mongodb to store electron and discharge.redisUrl
: string, redis to store bull queue.statsRedisUrl
: (optional) string, redis to store statistics of job status.enableSlack
: boolean, enable slack notifications.slack
: object, slack noti settings.webhoolUrl
: string, webhook url from slack incoming webhook.channel
: string, slack channel to send noti.username
: string, slack sender's name to send noti.
How to start worker
const ElectricFlow = require('electric-flow')
const electricFlow = new ElectricFlow({})
const mainboard = new ElectricFlow.MainBoard({})
electrician.register(mainboard)
// init all mainboard connection and worker
electrician.worker()
How to apply middleware for api
example:
const express = require('express')
const ElectricFlow = require('electric-flow')
const electricFlow = new Electrician()
const app = express()
electricFlow.applyApiMiddleware({ app: server, basePath: '' })
The settings
fields are:
app
: Express app.basePath
: object, basePath for api and arena ui.
Shortcut for single task circuitboard
const singleTaskBoard = new CircuitBoard({
name: 'singleTask'
})
singleTaskBoard.initSingleTaskWithResistor(new Resistor({
name: 'resistor1',
consume: (e) => {
// throw new Error('throw update error')
return { result: 'sg1 result' }
},
next: 'ground'
}))
create powersource, resistor and circuitboard
const cboard = new CircuitBoard({
name: 'cboard'
})
// create powersource and add to circuitboard
cboard.usePowerSource(new PowerSource({
generate: () => ([{}, {}, {}]), // generate 3 task
next: 'resistor1' // redirect to resistor with name
}))
// create resistor and add to circuitboard
cboard.addResistor(new Resistor({
name: 'resistor1',
consume: async (e) => {
// throw new Error('throw update error')
return { result: 'result1' }
},
next: 'resistor2' // redirect to resistor 2 after complete
}))
cboard.addResistor(new Resistor({
name: 'resistor2',
consume: (e) => {
return { result: 'result2' }
},
next: 'ground' // complete circuit with ground
}))
1.4.9
1 year ago
1.4.10
1 year ago
1.4.8
2 years ago
1.4.6
2 years ago
1.4.7
2 years ago
1.4.5
2 years ago
1.4.4
2 years ago
1.4.3-alpha.1
3 years ago
1.4.3-alpha.0
3 years ago
1.4.1
3 years ago
1.2.6
3 years ago
1.2.5
3 years ago
1.2.4
3 years ago
1.3.2
3 years ago
1.2.3
3 years ago
1.4.0
3 years ago
1.3.1
3 years ago
1.2.2
3 years ago
1.3.0
3 years ago
1.2.1
4 years ago
1.2.1-rc.0
4 years ago
1.1.15
5 years ago
1.1.14
5 years ago
1.1.14-rc1
5 years ago
1.1.13-rc1
5 years ago
1.1.12
5 years ago
1.1.11
5 years ago
1.1.10
5 years ago
1.1.9
5 years ago
1.1.8
5 years ago
1.1.7
5 years ago
1.1.6
5 years ago
1.1.5
5 years ago
1.1.4
5 years ago
1.1.2
6 years ago
1.1.1
6 years ago
1.1.0
6 years ago
1.0.3
6 years ago
1.0.2
6 years ago
1.0.1
6 years ago
1.0.0
6 years ago