Skip to content

Commit

Permalink
Change example to TS
Browse files Browse the repository at this point in the history
  • Loading branch information
felixmosh committed Apr 21, 2021
1 parent ebe6f8b commit dbf995e
Show file tree
Hide file tree
Showing 3 changed files with 1,633 additions and 1,654 deletions.
25 changes: 14 additions & 11 deletions example.js → example.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
const { setQueues, router, BullMQAdapter } = require('./dist/index')
const { Queue: QueueMQ, Worker, QueueScheduler } = require('bullmq')
const Queue3 = require('bull')
const app = require('express')()
import Queue3 from 'bull'
import { Queue as QueueMQ, QueueScheduler, Worker } from 'bullmq'
import express from 'express'
import { BullMQAdapter, BullAdapter, router, setQueues } from './dist/index'

const sleep = (t) => new Promise((resolve) => setTimeout(resolve, t * 1000))
const app = express()

const sleep = (t: number) =>
new Promise((resolve) => setTimeout(resolve, t * 1000))

const redisOptions = {
port: 6379,
host: 'localhost',
password: '',
tls: false,
}

const createQueue3 = (name) => new Queue3(name, { redis: redisOptions })
const createQueueMQ = (name) => new QueueMQ(name, { connection: redisOptions })
const createQueue3 = (name: string) => new Queue3(name, { redis: redisOptions })
const createQueueMQ = (name: string) =>
new QueueMQ(name, { connection: redisOptions })

const run = async () => {
const exampleBullName = 'ExampleBull'
const exampleBull = createQueue3(exampleBullName)
const exampleBullMqName = 'ExampleBullMQ'
const exampleBullMq = createQueueMQ(exampleBullMqName)

setQueues([new BullMQAdapter(exampleBullMq)])
setQueues([new BullMQAdapter(exampleBullMq), new BullAdapter(exampleBull)])

exampleBull.process(async (job) => {
for (let i = 0; i <= 100; i++) {
Expand Down Expand Up @@ -52,7 +55,7 @@ const run = async () => {
})

app.use('/add', (req, res) => {
const opts = req.query.opts || {}
const opts = req.query.opts || ({} as any)

if (opts.delay) {
opts.delay = +opts.delay * 1000 // delay must be a number
Expand All @@ -78,4 +81,4 @@ const run = async () => {
})
}

run()
run().catch((e) => console.error(e))
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"build:routes": "yarn tsc",
"build:clean": "rm -rf ./static ./dist",
"start:dev:docker": "docker-compose up -d",
"start:dev:server": "nodemon example.js",
"start:dev:server": "ts-node-dev example.ts",
"start:dev:ui": "NODE_ENV=development webpack serve",
"start:dev": "yarn start:dev:docker && yarn start:dev:server",
"test": "yarn ts-node src/dockest",
Expand Down Expand Up @@ -98,7 +98,6 @@
"html-webpack-plugin": "^5.3.1",
"jest": "^26.6.3",
"mini-css-extract-plugin": "^1.3.9",
"nodemon": "^2.0.6",
"postcss-loader": "^5.2.0",
"postcss-preset-env": "^6.7.0",
"prettier": "^2.2.1",
Expand All @@ -111,6 +110,7 @@
"supertest": "^6.0.1",
"ts-jest": "^26.5.4",
"ts-node": "^9.1.0",
"ts-node-dev": "^1.1.6",
"typescript": "^4.2.3",
"webpack": "^5.27.1",
"webpack-cli": "^4.5.0",
Expand Down
Loading

0 comments on commit dbf995e

Please sign in to comment.