-
-
Notifications
You must be signed in to change notification settings - Fork 368
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add elysia adapter * chore: use typings from dist and remove Promise * chore: improve package and README * chore: improve elysia example * chore: use skipLibCheck (oven-sh/bun#8761) * change: author at package * chore: bumps
- Loading branch information
1 parent
6f3bdcc
commit f07c544
Showing
20 changed files
with
957 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Elysia example | ||
|
||
This example shows how to use [Elysia](https://elysiajs.com/) as a server for bull-board. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { createBullBoard } from "@bull-board/api"; | ||
import { BullMQAdapter } from "@bull-board/api/bullMQAdapter"; | ||
import { ElysiaAdapter } from "@bull-board/elysia"; | ||
import { Queue as QueueMQ, Worker } from "bullmq"; | ||
import Elysia from "elysia"; | ||
|
||
const sleep = (t: number) => | ||
new Promise((resolve) => setTimeout(resolve, t * 1000)); | ||
|
||
const redisOptions = { | ||
port: 6379, | ||
host: "localhost", | ||
password: "", | ||
}; | ||
|
||
const createQueueMQ = (name: string) => | ||
new QueueMQ(name, { connection: redisOptions }); | ||
|
||
async function setupBullMQProcessor(queueName: string) { | ||
new Worker( | ||
queueName, | ||
async (job) => { | ||
for (let i = 0; i <= 100; i++) { | ||
await sleep(Math.random()); | ||
await job.updateProgress(i); | ||
await job.log(`Processing job at interval ${i}`); | ||
|
||
if (Math.random() * 200 < 1) throw new Error(`Random error ${i}`); | ||
} | ||
|
||
return { jobId: `This is the return value of job (${job.id})` }; | ||
}, | ||
{ connection: redisOptions }, | ||
); | ||
} | ||
|
||
const exampleBullMq = createQueueMQ("BullMQ"); | ||
|
||
await setupBullMQProcessor(exampleBullMq.name); | ||
|
||
const serverAdapter = new ElysiaAdapter("/ui"); | ||
|
||
createBullBoard({ | ||
queues: [new BullMQAdapter(exampleBullMq)], | ||
serverAdapter, | ||
}); | ||
|
||
const app = new Elysia() | ||
.use(serverAdapter.registerPlugin()) | ||
.get("/add", async ({ query }) => { | ||
await exampleBullMq.add("Add", { title: query.title }); | ||
|
||
return { ok: true }; | ||
}); | ||
|
||
app.listen(3000, ({ port, url }) => { | ||
/* eslint-disable no-console */ | ||
console.log(`Running on ${url.hostname}:${port}...`); | ||
console.log(`For the UI of instance1, open http://localhost:${port}/ui`); | ||
console.log("Make sure Redis is running on port 6379 by default"); | ||
console.log("To populate the queue, run:"); | ||
console.log(` curl http://localhost:${port}/add?title=Example`); | ||
/* eslint-enable no-console */ | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "bull-board-with-elysia", | ||
"type": "module", | ||
"version": "1.0.0", | ||
"description": "Example of how to use Elysia server with bull-board", | ||
"module": "index.ts", | ||
"scripts": { | ||
"start": "bun index.ts", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "kravetsone", | ||
"license": "ISC", | ||
"dependencies": { | ||
"@bull-board/elysia": "^5.20.1", | ||
"bullmq": "^4.6.0", | ||
"elysia": "^1.0.22" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"compilerOptions": { | ||
"lib": ["ESNext"], | ||
"module": "ESNext", | ||
"target": "ESNext", | ||
"moduleResolution": "Bundler", | ||
"esModuleInterop": true, | ||
"strict": true, | ||
"skipLibCheck": true, | ||
"allowSyntheticDefaultImports": true, | ||
"rootDir": "./src", | ||
"noEmit": true | ||
}, | ||
"include": ["src"] | ||
} |
Oops, something went wrong.