Improve large playlist stability and Spotify item endpoint
This commit is contained in:
@@ -168,7 +168,7 @@ export class SpotifyApiService {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`https://api.spotify.com/v1/playlists/${playlistId}/tracks?offset=${offset}&limit=100&fields=items(track(id,name,artists,preview_url,album(images))),next`,
|
`https://api.spotify.com/v1/playlists/${playlistId}/items?offset=${offset}&limit=100&fields=items(track(id,name,artists,preview_url,album(images))),next`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${accessToken}`,
|
Authorization: `Bearer ${accessToken}`,
|
||||||
|
|||||||
@@ -4,8 +4,18 @@ import { Job } from 'bullmq';
|
|||||||
import { TrackService } from './track.service';
|
import { TrackService } from './track.service';
|
||||||
import { TrackEntity } from './track.entity';
|
import { TrackEntity } from './track.entity';
|
||||||
|
|
||||||
|
function getSearchDelayMs(): number {
|
||||||
|
const parsed = Number(process.env.YT_SEARCH_DELAY_MS || 5000);
|
||||||
|
|
||||||
|
if (!Number.isFinite(parsed) || parsed < 0) {
|
||||||
|
return 5000;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Math.max(1000, Math.min(30000, Math.floor(parsed)));
|
||||||
|
}
|
||||||
|
|
||||||
@Processor('track-search-processor', {
|
@Processor('track-search-processor', {
|
||||||
concurrency: 2,
|
concurrency: 1,
|
||||||
})
|
})
|
||||||
export class TrackSearchProcessor extends WorkerHost {
|
export class TrackSearchProcessor extends WorkerHost {
|
||||||
private readonly logger = new Logger(TrackSearchProcessor.name);
|
private readonly logger = new Logger(TrackSearchProcessor.name);
|
||||||
@@ -14,13 +24,14 @@ export class TrackSearchProcessor extends WorkerHost {
|
|||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
async process(job: Job<TrackEntity, void, string>): Promise<void> {
|
async process(job: Job<{ id: number }, void, string>): Promise<void> {
|
||||||
if (!job.data?.id) {
|
const delayMs = getSearchDelayMs();
|
||||||
this.logger.warn(`Skipping malformed search job ${job.id}`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.logger.debug(`Processing search job ${job.id} for track ${job.data.id}`);
|
this.logger.debug(
|
||||||
await this.trackService.findOnYoutube(job.data);
|
`Processing search job ${job.id} for track ${job.data.id}; pacing ${delayMs}ms`,
|
||||||
|
);
|
||||||
|
|
||||||
|
await new Promise((res) => setTimeout(res, delayMs));
|
||||||
|
await this.trackService.findOnYoutube({ id: job.data.id } as TrackEntity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user