Skip to content

Commit

Permalink
Move Status type to constants
Browse files Browse the repository at this point in the history
  • Loading branch information
Yurickh committed Jan 25, 2020
1 parent 4cf2720 commit 4799c34
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 38 deletions.
4 changes: 1 addition & 3 deletions src/@types/app.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { STATUSES } from '../ui/components/constants'
import { Status } from '../ui/components/constants'
import { Queue, JobOptions } from 'bull'
import { Queue as QueueMq, JobsOptions, Job as JobMq } from 'bullmq'

export type Status = keyof typeof STATUSES

export interface BullBoardQueue {
queue: Queue | QueueMq
}
Expand Down
56 changes: 24 additions & 32 deletions src/ui/components/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,25 @@ export const STATUSES = {
waiting: 'waiting',
}

export const FIELDS = {
[STATUSES.active]: [
'attempts',
'data',
'id',
'name',
'opts',
'progress',
'timestamps',
],
[STATUSES.completed]: [
export type Status = keyof typeof STATUSES

export type Field =
| 'attempts'
| 'data'
| 'id'
| 'name'
| 'opts'
| 'progress'
| 'timestamps'
| 'delay'
| 'failedReason'
| 'retry'
// REVIEW: this one is in none of the statuses, but we have a handler for it?
| 'finish'

export const FIELDS: Record<Status, Field[]> = {
active: ['attempts', 'data', 'id', 'name', 'opts', 'progress', 'timestamps'],
completed: [
'attempts',
'data',
'id',
Expand All @@ -27,16 +35,8 @@ export const FIELDS = {
'progress',
'timestamps',
],
[STATUSES.delayed]: [
'attempts',
'data',
'delay',
'id',
'name',
'opts',
'timestamps',
],
[STATUSES.failed]: [
delayed: ['attempts', 'data', 'delay', 'id', 'name', 'opts', 'timestamps'],
failed: [
'attempts',
'failedReason',
'id',
Expand All @@ -45,15 +45,7 @@ export const FIELDS = {
'retry',
'timestamps',
],
[STATUSES.latest]: [
'attempts',
'data',
'id',
'name',
'opts',
'progress',
'timestamps',
],
[STATUSES.paused]: ['attempts', 'data', 'id', 'name', 'opts', 'timestamps'],
[STATUSES.waiting]: ['data', 'id', 'name', 'opts', 'timestamps'],
latest: ['attempts', 'data', 'id', 'name', 'opts', 'progress', 'timestamps'],
paused: ['attempts', 'data', 'id', 'name', 'opts', 'timestamps'],
waiting: ['data', 'id', 'name', 'opts', 'timestamps'],
}
8 changes: 5 additions & 3 deletions src/ui/components/hooks/useStore.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { useEffect, useRef, useState } from 'react'
import qs from 'querystring'

import { Status } from '../constants'
import * as api from '../../../@types/api'
import { AppQueue, Status } from '../../../@types/app'
import { AppQueue, AppJob } from '../../../@types/app'

const interval = 5000

Expand All @@ -14,7 +16,7 @@ type SelectedStatuses = Record<AppQueue['name'], Status>

export interface Store {
state: State
retryJob: (queueName: string) => (job: { id: string }) => () => Promise<void>
retryJob: (queueName: string) => (job: AppJob) => () => Promise<void>
retryAll: (queueName: string) => () => Promise<void>
cleanAllDelayed: (queueName: string) => () => Promise<void>
cleanAllFailed: (queueName: string) => () => Promise<void>
Expand Down Expand Up @@ -60,7 +62,7 @@ export const useStore = (basePath: string): Store => {
.then(res => (res.ok ? res.json() : Promise.reject(res)))
.then(data => setState({ data, loading: false }))

const retryJob = (queueName: string) => (job: { id: string }) => () =>
const retryJob = (queueName: string) => (job: AppJob) => () =>
fetch(`${basePath}/queues/${queueName}/${job.id}/retry`, {
method: 'put',
}).then(update)
Expand Down

0 comments on commit 4799c34

Please sign in to comment.