Skip to content

Commit 70d8ba0

Browse files
chore: wip
1 parent 1d3cf9c commit 70d8ba0

File tree

4 files changed

+97
-33
lines changed

4 files changed

+97
-33
lines changed

resources/components/Queue/QueueTable.vue

Lines changed: 76 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,78 @@
11
<script setup lang="ts">
22
const queueStore = useQueueStore()
33
4+
interface QueuePayload {
5+
path: string
6+
name: string
7+
maxTries: number
8+
timeOut: number | null
9+
timeOutAt: Date | null
10+
params: any
11+
classPayload: string
12+
}
13+
414
onMounted(async () => {
515
await queueStore.fetchQueues()
616
})
17+
18+
function parseName(payload: string): string {
19+
try {
20+
const parsedPayload = JSON.parse(payload) as QueuePayload
21+
22+
return parsedPayload.name
23+
24+
} catch (e) {
25+
console.error('Error parsing classPayload:', e)
26+
27+
return ''
28+
}
29+
}
30+
31+
function parseDescription(payload: string): string {
32+
try {
33+
const parsedPayload = JSON.parse(payload) as QueuePayload
34+
35+
const parsedClassPayload = JSON.parse(parsedPayload.classPayload) as any
36+
37+
return parsedClassPayload.description
38+
39+
} catch (e) {
40+
console.error('Error parsing classPayload:', e)
41+
42+
return ''
43+
}
44+
}
45+
46+
function parseTries(payload: string): number {
47+
try {
48+
const parsedPayload = JSON.parse(payload) as QueuePayload
49+
50+
const parsedClassPayload = JSON.parse(parsedPayload.classPayload) as any
51+
52+
return Number(parsedClassPayload.tries)
53+
54+
} catch (e) {
55+
console.error('Error parsing classPayload:', e)
56+
57+
return 0
58+
}
59+
}
60+
61+
62+
63+
function parsePath(payload: string): string {
64+
try {
65+
const parsedPayload = JSON.parse(payload) as QueuePayload
66+
67+
return parsedPayload.path
68+
69+
} catch (e) {
70+
console.error('Error parsing classPayload:', e)
71+
72+
return ''
73+
}
74+
}
75+
776
</script>
877
<template>
978
<div class="px-4 pt-12 lg:px-8 sm:px-6">
@@ -62,29 +131,29 @@ onMounted(async () => {
62131
</thead>
63132

64133
<tbody class="bg-white divide-y divide-gray-200">
65-
<tr>
134+
<tr v-for="queue in queueStore.queues" :key="queue.id">
66135
<td class="whitespace-nowrap py-4 pl-4 pr-3 text-sm text-gray-900 font-medium sm:pl-6">
67-
Example Job
136+
{{ parseName(queue.payload) }}
68137
</td>
69138

70139
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">
71-
Demo job that runs every minute
140+
{{ parseDescription(queue.payload) }}
72141
</td>
73142

74143
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500 font-mono">
75-
./app/Jobs/ExampleJob.ts
144+
{{ parsePath(queue.payload) }}
76145
</td>
77146

78147
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">
79-
3
148+
{{ parseTries(queue.payload) }}
80149
</td>
81150

82151
<td class="whitespace-nowrap px-3 py-4 text-right text-sm text-gray-500">
83-
01-03-2023 08:23:15
152+
{{ queue.created_at }}
84153
</td>
85154

86155
<td class="whitespace-nowrap px-3 py-4 text-right text-sm text-gray-500">
87-
04-19-2022 09:04:20
156+
{{ queue.updated_at }}
88157
</td>
89158

90159
<td class="relative whitespace-nowrap py-4 pl-3 pr-4 text-right text-sm font-medium sm:pr-6">

resources/stores/queue.ts

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { ref, type Ref } from 'vue'
2+
13
interface Queue {
24
id?: number
35
queue: string
@@ -9,19 +11,11 @@ interface Queue {
911
updated_at?: string | null
1012
}
1113

12-
interface State {
13-
queues: Queue[]
14-
}
1514

16-
export const useQueueStore = defineStore('queue', {
17-
state: (): State => {
18-
return {
19-
queues: [],
20-
}
21-
},
15+
export const useQueueStore = defineStore('queue', () => {
16+
const queues: Ref<Queue[]> = ref([])
2217

23-
actions: {
24-
async fetchQueues(): Promise<void> {
18+
async function fetchQueues(): Promise<void> {
2519
const url = `http://localhost:3008/queues`
2620

2721
const response = await fetch(url, {
@@ -32,15 +26,15 @@ export const useQueueStore = defineStore('queue', {
3226
},
3327
})
3428

35-
const queues = await response.json() as Queue[]
29+
const res = await response.json() as Queue[]
3630

37-
this.queues = queues
38-
},
39-
},
31+
queues.value = res
32+
}
4033

41-
getters: {
42-
getQueues: state => state.queues
43-
},
34+
return {
35+
queues,
36+
fetchQueues
37+
}
4438
})
4539

4640
if (import.meta.hot)

storage/framework/core/queue/src/process.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import { Job } from '../../../orm/src/models/Job'
66
import { runJob } from './job'
77

88
interface QueuePayload {
9-
displayName: string
9+
path: string
1010
name: string
1111
maxTries: number
1212
timeOut: number | null
1313
timeOutAt: Date | null
14-
payload: any
14+
params: any,
15+
classPayload: string
1516
}
1617

1718
export async function processJobs(queue: string | undefined): Promise<Ok<string, never>> {
@@ -44,27 +45,27 @@ async function executeJobs(queue: string | undefined): Promise<void> {
4445
const body: QueuePayload = JSON.parse(job.payload)
4546
const currentAttempts = job.attempts || 0
4647

47-
log.info(`Running job: ${body.displayName}`)
48+
log.info(`Running job: ${body.path}`)
4849

4950
await updateJobAttempts(job, currentAttempts)
5051

5152
try {
5253
await runJob(body.name, {
5354
queue: job.queue,
54-
payload: body.payload,
55+
payload: body.params,
5556
context: '',
5657
maxTries: body.maxTries,
5758
timeout: 60,
5859
})
5960

6061
await job.delete()
61-
log.info(`Successfully ran job: ${body.displayName}`)
62+
log.info(`Successfully ran job: ${body.path}`)
6263
}
6364
catch (error) {
6465
const stringifiedError = JSON.stringify(error)
6566

6667
storeFailedJob(job, stringifiedError)
67-
log.error(`Job failed: ${body.displayName}`, stringifiedError)
68+
log.error(`Job failed: ${body.path}`, stringifiedError)
6869
}
6970
}
7071
}

storage/framework/core/queue/src/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ export async function storeJob(name: string, options: QueueOption): Promise<void
1111
const importedJob = (await import(path.appPath(`Jobs/${name}.ts`))).default
1212

1313
const payloadJson = JSON.stringify({
14-
displayName: `app/Jobs/${name}.ts`,
14+
path: `app/Jobs/${name}.ts`,
1515
name,
1616
maxTries: options.tries || 1,
1717
timeout: null,
1818
timeoutAt: null,
19-
payload: options.payload || {},
19+
params: options.payload || {},
2020
classPayload: JSON.stringify(importedJob),
2121
})
2222

0 commit comments

Comments
 (0)