Skip to content

Commit

Permalink
Add return value 184 (#190)
Browse files Browse the repository at this point in the history
* Bump deps to latest
Clean up deps
Add css minification on prod
Enable vendor chunk

* feat: add return value, closes #184
  • Loading branch information
felixmosh authored Dec 9, 2020
1 parent 1c48270 commit eb47e1c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
12 changes: 7 additions & 5 deletions example.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { Queue: QueueMQ, Worker, QueueScheduler } = require('bullmq')
const Queue3 = require('bull')
const app = require('express')()

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

const redisOptions = {
port: 6379,
Expand All @@ -12,8 +12,8 @@ const redisOptions = {
tls: false,
}

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

const run = async () => {
const exampleBullName = 'ExampleBull'
Expand All @@ -23,7 +23,7 @@ const run = async () => {

setQueues([new BullMQAdapter(exampleBullMq)])

exampleBull.process(async job => {
exampleBull.process(async (job) => {
for (let i = 0; i <= 100; i++) {
await sleep(Math.random())
job.progress(i)
Expand All @@ -36,12 +36,14 @@ const run = async () => {
})
await queueScheduler.waitUntilReady()

new Worker(exampleBullMqName, async job => {
new Worker(exampleBullMqName, async (job) => {
for (let i = 0; i <= 100; i++) {
await sleep(Math.random())
await job.updateProgress(i)

if (Math.random() * 200 < 1) throw new Error(`Random error ${i}`)

return { jobId: `This is the return value of job (${job.id})` }
}
})

Expand Down
1 change: 1 addition & 0 deletions src/@types/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export interface AppJob {
data: JobMq['data']
name: JobMq['name']
delay: number | undefined
returnValue: string | Record<string | number, any> | null
}

export interface AppQueue {
Expand Down
1 change: 1 addition & 0 deletions src/routes/queues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const formatJob = (job: Job | JobMq): app.AppJob => {
opts: jobProps.opts,
data: jobProps.data,
name: jobProps.name,
returnValue: jobProps.returnvalue,
}
}

Expand Down
10 changes: 8 additions & 2 deletions src/ui/hooks/useDetailsTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,18 @@ export function useDetailsTabs(currentStatus: Status) {
selectTab: () => setSelectedTabIdx(index),
})),
selectedTab,
getTabContent: ({ data, opts, failedReason, stacktrace }: AppJob) => {
getTabContent: ({
data,
returnValue,
opts,
failedReason,
stacktrace,
}: AppJob) => {
switch (selectedTab) {
case 'Data':
return (
<Highlight language="json">
{JSON.stringify(data, null, 2)}
{JSON.stringify({ data, returnValue }, null, 2)}
</Highlight>
)
case 'Options':
Expand Down

0 comments on commit eb47e1c

Please sign in to comment.