-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement dead letter endpoints
* Implement backend api endpoints for dead letter CRUD * Include dead letter queue count in client status data * Implement dead letter client view * Partially working retry/remove actions for client (request is OK, RTK not working for update yet)
- Loading branch information
Showing
9 changed files
with
232 additions
and
30 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
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
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,61 @@ | ||
import React, {useCallback} from 'react'; | ||
import PlayDisplay from "../components/PlayDisplay"; | ||
import {recentIncludes} from "../../core/Atomic"; | ||
import {useSearchParams} from "react-router-dom"; | ||
import { | ||
useGetDeadQuery, | ||
//useLazyProcessDeadSingleQuery, | ||
//useLazyRemoveDeadSingleQuery, | ||
useRemoveDeadSingleMutation, | ||
useProcessDeadSingleMutation | ||
} from "./deadLetterDucks"; | ||
import dayjs from "dayjs"; | ||
import {Simulate} from "react-dom/test-utils"; | ||
import click = Simulate.click; | ||
|
||
const displayOpts = { | ||
include: recentIncludes, | ||
includeWeb: true | ||
} | ||
|
||
const dead = () => { | ||
let [searchParams, setSearchParams] = useSearchParams(); | ||
const { | ||
data = [], | ||
error, | ||
isLoading, | ||
isSuccess | ||
} = useGetDeadQuery({name: searchParams.get('name'), type: searchParams.get('type')}); | ||
|
||
// const [removeDeadFetch] = useLazyRemoveDeadSingleQuery(); | ||
// const [retryDeadFetch] = useLazyProcessDeadSingleQuery(); | ||
const [removeDeadFetch] = useRemoveDeadSingleMutation(); | ||
const [retryDeadFetch] = useProcessDeadSingleMutation(); | ||
|
||
const retryDead = useCallback((id: string) => retryDeadFetch({name: searchParams.get('name'), type: searchParams.get('type'), id}), [retryDeadFetch, searchParams]); | ||
const removeDead = useCallback((id: string) => removeDeadFetch({name: searchParams.get('name'), type: searchParams.get('type'), id}), [removeDeadFetch, searchParams]); | ||
|
||
return ( | ||
<div className="grid"> | ||
<div className="shadow-md rounded bg-gray-500 text-white"> | ||
<div className="p-3 font-semibold bg-gray-700 text-white"> | ||
<h2>Failed Scrobbles | ||
</h2> | ||
</div> | ||
<div className="p-5"> | ||
{isSuccess && !isLoading && data.length === 0 ? 'No failed scrobbles!' : null} | ||
<ul>{data.map(x => (<li className="my-2.5" key={x.id}> | ||
<div className="text-lg"><PlayDisplay data={x.play} buildOptions={displayOpts}/></div> | ||
<div><span className="font-semibold">Source</span>:{x.source.replace('Source -', '')}</div> | ||
<div><span className="font-semibold">Last Retried</span>: {x.lastRetry === undefined ? 'Never' : dayjs.duration(dayjs().diff(dayjs(x.lastRetry))).humanize(true)}</div> | ||
<div><span className="font-semibold">Retries</span>: {x.retries}</div> | ||
<div onClick={() => retryDead(x.id)} className="capitalize underline cursor-pointer">Retry</div> | ||
<div onClick={() => removeDead(x.id)} className="capitalize underline cursor-pointer">Remove</div> | ||
</li>))}</ul> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default dead; |
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,47 @@ | ||
import {createApi, fetchBaseQuery} from "@reduxjs/toolkit/dist/query/react/index"; | ||
import {DeadLetterScrobble, JsonPlayObject} from "../../core/Atomic"; | ||
import {id} from "common-tags"; | ||
|
||
type DeadResponse = DeadLetterScrobble<JsonPlayObject, string>[]; | ||
export const deadApi = createApi({ | ||
reducerPath: 'deadApi', | ||
baseQuery: fetchBaseQuery({ baseUrl: '/api/' }), | ||
tagTypes: ['DeadLetters'], | ||
endpoints: (builder) => ({ | ||
getDead: builder.query<DeadResponse, {name: string, type: string}>({ | ||
query: (params) => `dead?name=${params.name}&type=${params.type}`, | ||
providesTags: ['DeadLetters'] | ||
}), | ||
processDeadSingle: builder.mutation<DeadLetterScrobble<JsonPlayObject, string> | undefined, {name: string, type: string, id: string}>({ | ||
query:(params) => ({ | ||
url: `/dead/${params.id}`, | ||
method: 'PUT', | ||
params: { | ||
name: params.name, | ||
type: params.type | ||
} | ||
}) | ||
}), | ||
removeDeadSingle: builder.mutation<DeadLetterScrobble<JsonPlayObject, string> | undefined, {name: string, type: string, id: string}>({ | ||
query:(params) => ({ | ||
url: `/dead/${params.id}`, | ||
method: 'DELETE', | ||
params: { | ||
name: params.name, | ||
type: params.type | ||
}, | ||
transformResponse: (response, meta, arg) => { | ||
if(response === undefined) { | ||
return undefined; | ||
} else { | ||
return response; | ||
} | ||
}, | ||
invalidatesTags: ['DeadLetters'] | ||
}), | ||
}), | ||
}), | ||
}); | ||
|
||
//export const { useGetDeadQuery, useLazyProcessDeadSingleQuery, useLazyRemoveDeadSingleQuery } = deadApi; | ||
export const { useGetDeadQuery, useProcessDeadSingleMutation, useRemoveDeadSingleMutation } = deadApi; |
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
Oops, something went wrong.