-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchallenges.service.ts
More file actions
757 lines (669 loc) · 22.9 KB
/
Copy pathchallenges.service.ts
File metadata and controls
757 lines (669 loc) · 22.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
import {
includes,
isEmpty,
find,
camelCase,
groupBy,
orderBy,
uniqBy,
} from 'lodash';
import {
BadRequestException,
ConflictException,
Injectable,
} from '@nestjs/common';
import { isUUID } from 'class-validator';
import { ENV_CONFIG } from 'src/config';
import { Logger } from 'src/shared/global';
import {
Challenge,
ChallengeResource,
ChallengeReview,
Prize,
PrizeType,
ResourceRole,
Winner,
} from './models';
import { BillingAccountsService } from 'src/shared/topcoder/billing-accounts.service';
import { TopcoderM2MService } from 'src/shared/topcoder/topcoder-m2m.service';
import { ChallengeStatuses } from 'src/dto/challenge.dto';
import { PaymentStatus } from 'src/dto/payment.dto';
import {
CHALLENGE_BUDGET_SYNC_SKIP_ATTRIBUTE,
WinningsService,
} from '../winnings/winnings.service';
import {
WinningRequestDto,
WinningsCategory,
WinningsType,
} from 'src/dto/winning.dto';
import { WinningsRepository } from '../repository/winnings.repo';
import { PrismaService } from 'src/shared/global/prisma.service';
interface PaymentPayload {
handle: string;
amount: number;
userId: string;
type: WinningsCategory;
currency: PrizeType;
description?: string;
status?: PaymentStatus;
}
const placeToOrdinal = (place: number) => {
if (place === 1) return '1st';
if (place === 2) return '2nd';
if (place === 3) return '3rd';
return `${place}th`;
};
const PAYMENT_TYPE_METADATA_NAME = 'payment_type';
const PAYMENT_TYPE_TO_CATEGORY: Record<string, WinningsCategory> = {
taas: WinningsCategory.TAAS_PAYMENT,
topgear: WinningsCategory.TOPGEAR_PAYMENT,
};
const CANCELLED_CHALLENGE_STATUSES = [
ChallengeStatuses.Canceled,
ChallengeStatuses.CancelledFailedReview,
ChallengeStatuses.CancelledFailedScreening,
ChallengeStatuses.CancelledZeroSubmissions,
ChallengeStatuses.CancelledWinnerUnresponsive,
ChallengeStatuses.CancelledClientRequest,
ChallengeStatuses.CancelledRequirementsInfeasible,
ChallengeStatuses.CancelledZeroRegistrations,
ChallengeStatuses.CancelledPaymentFailed,
].map((status) => status.toLowerCase());
const { TOPCODER_API_V6_BASE_URL: TC_API_BASE, TGBillingAccounts } = ENV_CONFIG;
/**
* Determines whether a challenge status represents a cancelled challenge.
*
* @param status Challenge status returned by challenge-api-v6.
* @returns True when the status is one of the cancelled challenge states used
* by challenge-api-v6.
*/
function isCancelledChallengeStatus(status?: string): boolean {
return status
? CANCELLED_CHALLENGE_STATUSES.includes(status.toLowerCase())
: false;
}
@Injectable()
export class ChallengesService {
private readonly logger = new Logger(ChallengesService.name);
constructor(
private readonly prisma: PrismaService,
private readonly m2MService: TopcoderM2MService,
private readonly baService: BillingAccountsService,
private readonly winningsService: WinningsService,
private readonly winningsRepo: WinningsRepository,
) {}
private getMetadataPaymentCategory(
challenge: Challenge,
): WinningsCategory | undefined {
const metadataPaymentCategory = challenge.metadata?.find(
({ name, value }) =>
name?.toLowerCase() === PAYMENT_TYPE_METADATA_NAME &&
value &&
PAYMENT_TYPE_TO_CATEGORY[value.toLowerCase()],
);
if (metadataPaymentCategory?.value) {
return PAYMENT_TYPE_TO_CATEGORY[
metadataPaymentCategory.value.toLowerCase()
];
}
return undefined;
}
private getDefaultWinnerCategory(challenge: Challenge): WinningsCategory {
const metadataPaymentCategory = this.getMetadataPaymentCategory(challenge);
if (metadataPaymentCategory) {
return metadataPaymentCategory;
}
return challenge.task.isTask
? WinningsCategory.TASK_PAYMENT
: WinningsCategory.CONTEST_PAYMENT;
}
private getReviewerPaymentCategory(
challenge: Challenge,
currency?: PrizeType,
): WinningsCategory {
if (currency !== PrizeType.USD) {
return WinningsCategory.POINTS_AWARD;
}
return this.getMetadataPaymentCategory(challenge) ===
WinningsCategory.TOPGEAR_PAYMENT
? WinningsCategory.TOPGEAR_PAYMENT
: WinningsCategory.REVIEW_BOARD_PAYMENT;
}
/**
* Resolves the explicit payment status for task payments generated from
* challenge-api-v6 challenge data.
*
* @param challenge Challenge details returned by challenge-api-v6.
* @param category Winnings category selected for the generated payment.
* @param currency Prize currency selected for the generated payment.
* @returns OWED for USD TAAS task payments, ON_HOLD_ADMIN for other USD task
* payments, and undefined when standard payout-readiness rules should apply.
* @throws This method does not throw.
*/
private getTaskPaymentStatus(
challenge: Challenge,
category: WinningsCategory,
currency?: PrizeType,
): PaymentStatus | undefined {
if (!challenge.task?.isTask || currency !== PrizeType.USD) {
return undefined;
}
return category === WinningsCategory.TAAS_PAYMENT
? PaymentStatus.OWED
: PaymentStatus.ON_HOLD_ADMIN;
}
async getChallenge(challengeId: string) {
if (!isUUID(challengeId)) {
throw new BadRequestException(
'Invalid challengeId provided! Uuid expected!',
);
}
const requestUrl = `${TC_API_BASE}/challenges/${challengeId}`;
try {
const challenge = await this.m2MService.m2mFetch<Challenge>(requestUrl);
return challenge;
} catch (e) {
this.logger.error(
`Challenge ${challengeId} details couldn't be fetched!`,
e,
);
}
}
async getChallengeReviews(challengeId: string) {
const requestUrl = `${TC_API_BASE}/reviews?challengeId=${challengeId}&status=COMPLETED&thin=true&perPage=9999`;
try {
const resposne = await this.m2MService.m2mFetch<{
data: ChallengeReview[];
}>(requestUrl);
return resposne.data;
} catch (e) {
this.logger.error(
`Challenge reviews couldn't be fetched for challenge ${challengeId}!`,
e.message,
e.status,
);
}
}
async getChallengeResources(challengeId: string) {
try {
const resources = await this.m2MService.m2mFetch<ChallengeResource[]>(
`${TC_API_BASE}/resources?challengeId=${challengeId}`,
);
const resourceRoles = await this.m2MService.m2mFetch<ResourceRole[]>(
`${TC_API_BASE}/resource-roles`,
);
const rolesMap = resourceRoles.reduce(
(map, role) => {
map[role.id] = camelCase(role.name);
return map;
},
{} as { [key: string]: string },
);
return groupBy(resources, (r) => rolesMap[r.roleId]) as {
[role: string]: ChallengeResource[];
};
} catch (e) {
this.logger.error(
`Challenge resources for challenge ${challengeId} couldn't be fetched!`,
e,
);
}
}
generateWinnersPayments(
challenge: Challenge,
winners: Winner[],
prizes: Prize[],
type?: WinningsCategory,
): PaymentPayload[] {
if (isCancelledChallengeStatus(challenge.status)) {
return [];
}
const defaultCategory = this.getDefaultWinnerCategory(challenge);
return winners.map((winner) => {
const currency = prizes[winner.placement - 1].type;
const winType =
currency === PrizeType.USD
? (type ?? defaultCategory)
: WinningsCategory.POINTS_AWARD;
const status = this.getTaskPaymentStatus(challenge, winType, currency);
return {
handle: winner.handle,
amount: prizes[winner.placement - 1].value,
userId: winner.userId.toString(),
type: winType,
currency,
...(status ? { status } : {}),
description:
challenge.type === 'Task'
? challenge.name
: `${challenge.name} - ${type === WinningsCategory.CONTEST_CHECKPOINT_PAYMENT ? 'Checkpoint ' : ''}${placeToOrdinal(winner.placement)} Place`,
};
});
}
generateCheckpointWinnersPayments(challenge: Challenge): PaymentPayload[] {
const { prizeSets, checkpointWinners = [] } = challenge;
// generate placement payments
const checkpointPrizes = orderBy(
find(prizeSets, { type: 'CHECKPOINT' })?.prizes,
'value',
'desc',
);
if ((checkpointPrizes?.length ?? 0) < (checkpointWinners?.length ?? 0)) {
throw new Error(
'Task has incorrect number of checkpoint prizes! There are more checkpoint winners than checkpoint prizes!',
);
}
if (!checkpointPrizes?.length) {
return [];
}
if (checkpointPrizes.length < checkpointWinners.length) {
throw new Error(
'Task has incorrect number of checkpoint prizes! There are more checkpoint winners than prizes!',
);
}
return this.generateWinnersPayments(
challenge,
checkpointWinners,
checkpointPrizes,
WinningsCategory.CONTEST_CHECKPOINT_PAYMENT,
);
}
generatePlacementWinnersPayments(challenge: Challenge): PaymentPayload[] {
const { prizeSets, winners = [] } = challenge;
// generate placement payments
const placementPrizes = orderBy(
find(prizeSets, { type: 'PLACEMENT' })?.prizes,
'value',
'desc',
);
if (placementPrizes.length < winners.length) {
throw new Error(
'Task has incorrect number of placement prizes! There are more winners than prizes!',
);
}
return this.generateWinnersPayments(challenge, winners, placementPrizes);
}
generateCopilotPayment(
challenge: Challenge,
copilots: ChallengeResource[],
): PaymentPayload[] {
const copilotPrizes =
find(challenge.prizeSets, { type: 'COPILOT' })?.prizes ?? [];
if (!copilotPrizes.length || isCancelledChallengeStatus(challenge.status)) {
return [];
}
const placementPrizes = orderBy(
find(challenge.prizeSets, { type: 'PLACEMENT' })?.prizes,
'value',
'desc',
);
if (placementPrizes[0]?.type !== PrizeType.USD) {
const prizeType = placementPrizes[0].type;
this.logger.log(
`Skipping copilot payments generation for challenge ${challenge.id} with "${prizeType}" winning prize!`,
);
return [];
}
if (!copilots?.length) {
throw new Error('Task has a copilot prize but no copilot assigned!');
}
const copilotPrize = copilotPrizes[0];
const currency = copilotPrize.type;
const winType =
currency === PrizeType.USD
? WinningsCategory.COPILOT_PAYMENT
: WinningsCategory.POINTS_AWARD;
return copilots.map((copilot) => ({
handle: copilot.memberHandle,
amount: copilotPrizes[0].value,
userId: copilot.memberId.toString(),
type: winType,
currency,
description: `${challenge.name} - Copilot payment`,
}));
}
async generateReviewersPayments(
challenge: Challenge,
reviewers: ChallengeResource[],
): Promise<PaymentPayload[]> {
const placementPrizes = orderBy(
find(challenge.prizeSets, { type: 'PLACEMENT' })?.prizes,
'value',
'desc',
);
if (placementPrizes[0]?.type !== PrizeType.USD) {
const prizeType = placementPrizes[0].type;
this.logger.log(
`Skipping reviewers payments generation for challenge ${challenge.id} with "${prizeType}" winning prize!`,
);
return [];
}
// generate reviewer payments
const firstPlacePrize = placementPrizes?.[0]?.value ?? 0;
const hasMemberReviewers = find(challenge.reviewers, {
isMemberReview: true,
});
const challengeReviews = await this.getChallengeReviews(challenge.id);
if (
!hasMemberReviewers ||
!reviewers?.length ||
!challengeReviews?.length
) {
return [];
}
// For each challenge resource reviewer (can be main reviewer, approver, screener, etc)
// we get the reviewer's reviews
// and group them by phaseId
// based on the phaseId, we're fetching the correct challenge reviewer type (which has assigned payments coefficients)
// then we create the reviewe's payments for each phase based on the number of reviews done on each phase and the type of challenge reviewer assigned
return reviewers
.map((reviewer) => {
// Find all reviews that were performed by this reviewer (case-insensitive match)
const reviews = challengeReviews
.filter(
(r) =>
r.reviewerHandle.toLowerCase() ===
reviewer.memberHandle.toLowerCase(),
)
.map((r) => {
const challengePhase = find(challenge.phases, { id: r.phaseId });
if (!challengePhase) {
throw new Error(
`Failed to find challenge phase for review phase: ${r.phaseName} (${r.phaseId})`,
);
}
return {
...r,
// Find the corresponding phase object in the challenge definition using its id
phaseId: challengePhase?.phaseId,
};
});
// Group the reviews by their associated phaseId
return Object.entries(groupBy(reviews, 'phaseId')).map(
([phaseId, phaseReviews]) => {
// Find the reviewer entry in the challenge's reviewer list for this phase
// (be sure to exclude ai reviews)
const challengeReviewer = find(challenge.reviewers, {
isMemberReview: true,
phaseId,
});
if (!challengeReviewer) {
throw new Error(
`Failed to find challenge reviewer for phase: ${phaseReviews[0].phaseName} (${phaseId})`,
);
}
const placementPrize = placementPrizes?.[0];
const currency = placementPrize?.type;
const winType = this.getReviewerPaymentCategory(
challenge,
currency,
);
const status = this.getTaskPaymentStatus(
challenge,
winType,
currency,
);
return {
handle: reviewer.memberHandle,
userId: reviewer.memberId.toString(),
amount: Math.ceil(
(challengeReviewer.fixedAmount ?? 0) +
(challengeReviewer.baseCoefficient ?? 0) * firstPlacePrize +
(challengeReviewer.incrementalCoefficient ?? 0) *
firstPlacePrize *
phaseReviews.length,
),
type: winType,
currency: placementPrizes?.[0]?.type ?? PrizeType.USD,
...(status ? { status } : {}),
description: `${challenge.name} - ${phaseReviews[0].phaseName}`,
};
},
);
})
.flat();
}
async getChallengePayments(challenge: Challenge) {
this.logger.log(
`Generating payments for challenge ${challenge.name} (${challenge.id}).`,
);
const challengeResources = await this.getChallengeResources(challenge.id);
if (!challengeResources || isEmpty(challengeResources)) {
throw new Error('Missing challenge resources!');
}
const winnersPayments = this.generatePlacementWinnersPayments(challenge);
const checkpointPayments =
this.generateCheckpointWinnersPayments(challenge);
const copilotPayments = this.generateCopilotPayment(
challenge,
challengeResources.copilot,
);
let reviewersPayments: PaymentPayload[] = [];
try {
reviewersPayments = await this.generateReviewersPayments(
challenge,
uniqBy(
[
...(challengeResources.iterativeReviewer ?? []),
...(challengeResources.reviewer ?? []),
...(challengeResources.checkpointScreener ?? []),
...(challengeResources.checkpointReviewer ?? []),
...(challengeResources.screener ?? []),
...(challengeResources.approver ?? []),
],
'memberId',
),
);
} catch (error) {
this.logger.error(
`Failed to generate reviewers payments for challenge ${challenge.id}!`,
error.message,
);
}
const payments: PaymentPayload[] = [
...winnersPayments,
...checkpointPayments,
...copilotPayments,
...reviewersPayments,
];
const totalUsdAmount = payments.reduce(
(sum, payment) =>
sum + (payment.currency === PrizeType.USD ? payment.amount : 0),
0,
);
return payments.map((payment) => {
const paymentStatus =
payment.status ??
this.getTaskPaymentStatus(challenge, payment.type, payment.currency);
return {
winnerId: payment.userId.toString(),
type:
payment.currency === PrizeType.USD
? WinningsType.PAYMENT
: WinningsType.POINTS,
origin: 'Topcoder',
category: payment.type,
title: challenge.name,
description: payment.description || challenge.name,
externalId: challenge.id,
...(payment.status ? { status: payment.status } : {}),
details: [
{
totalAmount: payment.amount,
grossAmount: payment.amount,
installmentNumber: 1,
currency: payment.currency || PrizeType.USD,
billingAccount: `${challenge.billing.billingAccountId}`,
challengeFee: totalUsdAmount * challenge.billing.markup,
},
],
attributes: {
billingAccountId: challenge.billing.billingAccountId,
[CHALLENGE_BUDGET_SYNC_SKIP_ATTRIBUTE]: true,
payroll: includes(
TGBillingAccounts,
parseInt(challenge.billing.billingAccountId),
),
},
};
});
}
private async createPayments(challenge: Challenge, userId: string) {
const existingPayments = (
await this.winningsRepo.searchWinnings({
externalIds: [challenge.id],
} as WinningRequestDto)
)?.data?.winnings;
if (existingPayments?.length > 0) {
this.logger.log(
`Payments already exist for challenge ${challenge.id}, skipping payment generation`,
);
throw new Error(
`Payments already exist for challenge ${challenge.id}, skipping payment generation`,
);
}
const paymentTypes = [
...new Set(
challenge.prizeSets
.map((set) => set.prizes.map((prize) => prize.type))
.flat(),
),
];
// treat POINT as supported (persisted) payment type; other non-USD/POINT types are rewards
const isSupportedPayment = paymentTypes.some(
(type) => type === PrizeType.USD || type === PrizeType.POINT,
);
if (!isSupportedPayment) {
this.logger.log(
`Detected not supported payment type: ${paymentTypes.join(', ')}. Skipping payments generation for challenge ${challenge.name} (${challenge.id}).`,
);
return;
}
const payments = await this.getChallengePayments(challenge);
// compute USD totals for BA validation/locking (POINT payments are persisted but not billed)
const totalUsdAmount = payments.reduce(
(sum, payment) =>
sum +
(payment.details[0].currency === PrizeType.USD
? payment.details[0].totalAmount
: 0),
0,
);
const baValidation = {
challengeId: challenge.id,
billingAccountId: +challenge.billing.billingAccountId,
markup: challenge.billing.markup,
status: challenge.status,
totalPrizesInCents: totalUsdAmount * 100,
};
if (challenge.billing?.clientBillingRate != null) {
baValidation.markup = challenge.billing.clientBillingRate;
}
await Promise.all(
payments.map(async (p) => {
try {
await this.winningsService.createWinningWithPayments(p, userId);
} catch (e) {
this.logger.log(
`Failed to create winnings payment for user ${p.winnerId}!`,
e,
);
}
}),
);
this.logger.log('Task Completed. locking consumed budget', baValidation);
await this.baService.lockConsumeAmount(baValidation);
}
async generateChallengePayments(challengeId: string, userId: string) {
const challenge = await this.getChallenge(challengeId);
this.logger.log(`Fetched challenge ${challengeId}`);
if (!challenge) {
this.logger.error(`Challenge not found: ${challengeId}`);
throw new Error('Challenge not found!');
}
this.logger.log(
`Challenge ${challenge.id} - "${challenge.name}" with status "${challenge.status}" retrieved`,
);
const isPayableStatus =
challenge.status.toLowerCase() ===
ChallengeStatuses.Completed.toLowerCase() ||
isCancelledChallengeStatus(challenge.status);
if (!isPayableStatus) {
this.logger.error(
`Challenge ${challenge.id} isn't in a payable status: ${challenge.status}`,
);
throw new Error("Challenge isn't in a payable status!");
}
if (challenge.funChallenge === true) {
this.logger.log(
`Skipping payment generation for fun challenge ${challenge.id} (${challenge.name}).`,
);
return;
}
// need to read for update (LOCK the rows)
this.logger.log(`Attempting to acquire lock for challenge ${challenge.id}`);
try {
await this.prisma.challenge_lock.create({
data: { external_id: challenge.id },
});
this.logger.log(`Lock acquired for challenge ${challenge.id}`);
} catch (err: any) {
if (err.code === 'P2002') {
this.logger.log(`Challenge Lock already acquired for ${challenge.id}`);
// P2002 = unique constraint failed → lock already exists
throw new ConflictException(
`Challenge Lock already acquired for ${challenge.id}`,
);
}
this.logger.error(
`Failed to acquire lock for challenge ${challenge.id}`,
err.message ?? err,
);
throw err;
}
try {
this.logger.log(
`Starting payment creation for challenge ${challenge.id}`,
);
await this.createPayments(challenge, userId);
this.logger.log(
`Payment creation completed for challenge ${challenge.id}`,
);
} catch (error) {
this.logger.error(
`Error while creating payments for challenge ${challenge.id}`,
error.message ?? error,
);
if (
error &&
typeof error.message === 'string' &&
error.message.includes('Lock already acquired')
) {
this.logger.log(
`Conflict detected while creating payments for ${challenge.id}`,
);
throw new ConflictException(
'Another payment operation is in progress.',
);
} else {
throw error;
}
} finally {
try {
const result = await this.prisma.challenge_lock.deleteMany({
where: { external_id: challenge.id },
});
this.logger.log(
`Released lock for challenge ${challenge.id}. Rows deleted: ${result.count}`,
);
} catch (releaseErr) {
// swallow errors if lock was already released but log for observability
this.logger.error(
`Failed to release lock for challenge ${challenge.id}`,
releaseErr.message ?? releaseErr,
);
}
}
}
}