import { AppJob } from '@bull-board/api/typings/app' ; import { GetQueuesResponse } from '@bull-board/api/typings/responses' ; import Axios , { AxiosInstance , AxiosResponse } from 'axios' ; import { toast } from 'react-toastify' ; import { SelectedStatuses } from '../../typings/app' ; export class Api { private axios : AxiosInstance ; constructor ( { basePath } = { basePath : '' } ) { this . axios = Axios . create ( { baseURL : `${ basePath }/api` } ) ; this . axios . interceptors . response . use ( this . handleResponse , this . handleError ) ; } public getQueues ( { status , page , } ) { return this . axios . get ( `/queues` , { params : { ... status , page } } ) ; } public retryAll ( queueName ) { return this . axios . put ( `/queues/${ encodeURIComponent ( queueName ) }/retry` ) ; } public cleanAllDelayed ( queueName ) { return this . axios . put ( `/queues/${ encodeURIComponent ( queueName ) }/clean/delayed` ) ; } public cleanAllFailed ( queueName ) { return this . axios . put ( `/queues/${ encodeURIComponent ( queueName ) }/clean/failed` ) ; } public cleanAllCompleted ( queueName ) { return this . axios . put ( `/queues/${ encodeURIComponent ( queueName ) }/clean/completed` ) ; } public cleanJob ( queueName , jobId ) { return this . axios . put ( `/queues/${ encodeURIComponent ( queueName ) }/${ encodeURIComponent ( `${ jobId }` ) }/clean` ) ; } public retryJob ( queueName , jobId ) { return this . axios . put ( `/queues/${ encodeURIComponent ( queueName ) }/${ encodeURIComponent ( `${ jobId }` ) }/retry` ) ; } public promoteJob ( queueName , jobId ) { return this . axios . put ( `/queues/${ encodeURIComponent ( queueName ) }/${ encodeURIComponent ( `${ jobId }` ) }/promote` ) ; } public getJobLogs ( queueName , jobId ) { return this . axios . get ( `/queues/${ encodeURIComponent ( queueName ) }/${ encodeURIComponent ( `${ jobId }` ) }/logs` ) ; } public pauseQueue ( queueName ) { return this . axios . put ( `/queues/${ encodeURIComponent ( queueName ) }/pause` ) ; } public resumeQueue ( queueName ) { return this . axios . put ( `/queues/${ encodeURIComponent ( queueName ) }/resume` ) ; } private handleResponse ( response ) { return response . data ; } private async handleError ( error ) { if ( error . response . data ?. error ) { toast . error ( error . response . data ?. error , { autoClose : 5000 } ) ; } return Promise . resolve ( error . response . data ) ; } }