Skip to content

Commit

Permalink
feat: refresh monitored downloads before getting queue items (#994)
Browse files Browse the repository at this point in the history
Currently, we sync with sonarr/radarr with whatever value those return. Radarr/Sonarr syncs the
activity from the download clients every few minutes. This leads to inaccurate estimated download
times, because of the refresh delay with Jellyseerr and the *arrs.

This PR fixes this by making a request to the *arrs to refresh the monitored downloads just before
we get these downloads information.

re #866
  • Loading branch information
gauthier-th authored Oct 10, 2024
1 parent 96e1d40 commit 92ba262
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
6 changes: 3 additions & 3 deletions server/api/externalapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class ExternalAPI {
}
const data = await this.getDataFromResponse(response);

if (this.cache) {
if (this.cache && ttl !== 0) {
this.cache.set(cacheKey, data, ttl ?? DEFAULT_TTL);
}

Expand Down Expand Up @@ -120,7 +120,7 @@ class ExternalAPI {
}
const resData = await this.getDataFromResponse(response);

if (this.cache) {
if (this.cache && ttl !== 0) {
this.cache.set(cacheKey, resData, ttl ?? DEFAULT_TTL);
}

Expand Down Expand Up @@ -164,7 +164,7 @@ class ExternalAPI {
}
const resData = await this.getDataFromResponse(response);

if (this.cache) {
if (this.cache && ttl !== 0) {
this.cache.set(cacheKey, resData, ttl ?? DEFAULT_TTL);
}

Expand Down
27 changes: 20 additions & 7 deletions server/api/servarr/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,13 @@ class ServarrBase<QueueItemAppendT> extends ExternalAPI {

public getQueue = async (): Promise<(QueueItem & QueueItemAppendT)[]> => {
try {
const data = await this.get<QueueResponse<QueueItemAppendT>>(`/queue`, {
includeEpisode: 'true',
});
const data = await this.get<QueueResponse<QueueItemAppendT>>(
`/queue`,
{
includeEpisode: 'true',
},
0
);

return data.records;
} catch (e) {
Expand Down Expand Up @@ -193,15 +197,24 @@ class ServarrBase<QueueItemAppendT> extends ExternalAPI {
}
};

async refreshMonitoredDownloads(): Promise<void> {
await this.runCommand('RefreshMonitoredDownloads', {});
}

protected async runCommand(
commandName: string,
options: Record<string, unknown>
): Promise<void> {
try {
await this.post(`/command`, {
name: commandName,
...options,
});
await this.post(
`/command`,
{
name: commandName,
...options,
},
{},
0
);
} catch (e) {
throw new Error(`[${this.apiName}] Failed to run command: ${e.message}`);
}
Expand Down
2 changes: 2 additions & 0 deletions server/lib/downloadtracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class DownloadTracker {
});

try {
await radarr.refreshMonitoredDownloads();
const queueItems = await radarr.getQueue();

this.radarrServers[server.id] = queueItems.map((item) => ({
Expand Down Expand Up @@ -162,6 +163,7 @@ class DownloadTracker {
});

try {
await sonarr.refreshMonitoredDownloads();
const queueItems = await sonarr.getQueue();

this.sonarrServers[server.id] = queueItems.map((item) => ({
Expand Down

0 comments on commit 92ba262

Please sign in to comment.