Skip to content

Commit

Permalink
corrct return value
Browse files Browse the repository at this point in the history
  • Loading branch information
tcm390 committed Jan 12, 2025
1 parent 1adebb2 commit ee9accb
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe("ReservoirService", () => {
beforeEach(() => {
cacheManager = new MemoryCacheManager();
rateLimiter = new RateLimiter();
service = new ReservoirService("test-api-key", {
service = new ReservoirService({
cacheManager,
rateLimiter,
});
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-nft-collections/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const config = {
batchSize: 20, // Batch size for collection requests
};

async function createNFTCollectionsPlugin(): Promise<Plugin> {
function createNFTCollectionsPlugin(): Plugin {
// Initialize reusable CacheManager if caching is enabled
const cacheManager = config.caching?.enabled
? new MemoryCacheManager({
Expand Down
63 changes: 30 additions & 33 deletions packages/plugin-nft-collections/src/services/reservoir.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pRetry from "p-retry";
import pQueue from "p-queue";
// import pQueue from "p-queue";
import { PerformanceMonitor } from "../utils/performance";
import {
ErrorHandler,
Expand All @@ -23,7 +23,7 @@ interface ReservoirServiceConfig {
export class ReservoirService {
private cacheManager?: MemoryCacheManager;
private rateLimiter?: RateLimiter;
private queue: pQueue;
// private queue: pQueue;
private maxRetries: number;
private batchSize: number;
private performanceMonitor: PerformanceMonitor;
Expand All @@ -32,7 +32,8 @@ export class ReservoirService {
constructor(config: ReservoirServiceConfig = {}) {
this.cacheManager = config.cacheManager;
this.rateLimiter = config.rateLimiter;
this.queue = new pQueue({ concurrency: config.maxConcurrent || 5 });

// this.queue = new pQueue({ concurrency: config.maxConcurrent || 5 });
this.maxRetries = config.maxRetries || 3;
this.batchSize = config.batchSize || 20;
this.performanceMonitor = PerformanceMonitor.getInstance();
Expand Down Expand Up @@ -73,39 +74,35 @@ export class ReservoirService {
const reservoirApiKey = runtime.getSetting("RESERVOIR_API_KEY");

// Make the request with retries
const result = await this.queue.add(
() =>
pRetry(
async () => {
const response = await fetch(
`https://api.reservoir.tools${endpoint}?${new URLSearchParams(
params
).toString()}`,
{
headers: {
"x-api-key": reservoirApiKey,
},
}
);

if (!response.ok) {
throw new Error(
`Reservoir API error: ${response.status}`
);
}

return response.json();
},
const result = await pRetry(
async () => {
const response = await fetch(
`https://api.reservoir.tools${endpoint}?${new URLSearchParams(
params
).toString()}`,
{
retries: this.maxRetries,
onFailedAttempt: (error) => {
console.error(
`Attempt ${error.attemptNumber} failed. ${error.retriesLeft} retries left.`
);
headers: {
"x-api-key": reservoirApiKey,
},
}
),
{ priority }
);

if (!response.ok) {
throw new Error(
`Reservoir API error: ${response.status}`
);
}

return response.json();
},
{
retries: this.maxRetries,
onFailedAttempt: (error) => {
console.error(
`Attempt ${error.attemptNumber} failed. ${error.retriesLeft} retries left.`
);
},
}
);

// Cache the result
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-nft-collections/src/tests/services.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe("NFT Services", () => {
beforeEach(() => {
cacheManager = new MemoryCacheManager();
rateLimiter = new RateLimiter();
service = new ReservoirService("test-api-key", {
service = new ReservoirService({
cacheManager,
rateLimiter,
});
Expand Down

0 comments on commit ee9accb

Please sign in to comment.