@merkl/api 0.16.23 → 0.16.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -229,25 +229,37 @@ export class CampaignRepository {
229
229
  path: ["shouldIgnore"],
230
230
  equals: Prisma.AnyNull,
231
231
  },
232
- CampaignStatus: {
233
- some: {
234
- // The campaign is not currently processing or has been processing for too long
235
- OR: [
236
- {
237
- status: {
238
- not: RunStatus.PROCESSING,
239
- },
240
- computedUntil: { lt: currentTime - 10 * 60 }, // more than 10 min ago
232
+ OR: [
233
+ {
234
+ // First case: the campaign has no status so was never processed
235
+ CampaignStatus: {
236
+ none: {
237
+ computedUntil: { gte: 0 },
241
238
  },
242
- {
243
- status: RunStatus.PROCESSING,
244
- processingStarted: {
245
- lt: currentTime - MAX_COMPUTE_JOB_TIME, // more than 12 hours ago
246
- },
239
+ },
240
+ },
241
+ {
242
+ CampaignStatus: {
243
+ some: {
244
+ // The campaign is not currently processing or has been processing for too long
245
+ OR: [
246
+ {
247
+ status: {
248
+ not: RunStatus.PROCESSING,
249
+ },
250
+ computedUntil: { lt: currentTime - 10 * 60 }, // more than 10 min ago
251
+ },
252
+ {
253
+ status: RunStatus.PROCESSING,
254
+ processingStarted: {
255
+ lt: currentTime - MAX_COMPUTE_JOB_TIME, // more than 12 hours ago
256
+ },
257
+ },
258
+ ],
247
259
  },
248
- ],
260
+ },
249
261
  },
250
- },
262
+ ],
251
263
  },
252
264
  select: {
253
265
  campaignId: true,
@@ -156,8 +156,8 @@ export class CampaignService {
156
156
  }
157
157
  static async findCampaignsToProcess(distributionChainId) {
158
158
  return (await CampaignRepository.findCampaignsToProcess(distributionChainId))
159
- .filter(campaign => campaign.endTimestamp > campaign?.CampaignStatus?.[0]?.computedUntil)
160
- ?.sort((a, b) => Number(a.CampaignStatus?.[0]?.processingStarted - b.CampaignStatus?.[0]?.processingStarted));
159
+ .filter(campaign => campaign.endTimestamp > (campaign?.CampaignStatus?.[0]?.computedUntil ?? 0))
160
+ ?.sort((a, b) => Number((a.CampaignStatus?.[0]?.processingStarted ?? 0) - (b.CampaignStatus?.[0]?.processingStarted ?? 0)));
161
161
  }
162
162
  static async findNextCampaignToProcess(chainId) {
163
163
  const campaigns = await CampaignService.findCampaignsToProcess(chainId);