Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 5d48b55

Browse files
committed
Copilot payment retry.
1 parent 5e52611 commit 5d48b55

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

services/CopilotPaymentService.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ async function _checkAndReSchedule(event, payment) {
142142
// reschedule
143143
setTimeout(async () => {
144144
const kafka = require('../utils/kafka'); // eslint-disable-line
145-
await kafka.send(JSON.stringify(event));
145+
const eventToHandle = _.omit(event, ['project']);
146+
await kafka.send(JSON.stringify(eventToHandle));
146147
logger.debug('The event is scheduled for retry');
147148
}, config.RETRY_INTERVAL);
148149
return true;
@@ -218,11 +219,11 @@ async function handlePaymentAdd(event, payment) {
218219

219220
logger.debug(`challenge ${challengeId} has been activated!`);
220221
} catch (ex) {
221-
await dbHelper.remove(models.CopilotPayment, {
222-
id: {eq: payment.id}
222+
await dbHelper.update(models.CopilotPayment, payment.id, {
223+
status: 'challenge_creation_retried'
223224
});
224-
225-
await eventService.handleEventGracefully(event, payment, ex);
225+
const eventToHandle = _.omit(event, ['project']);
226+
await eventService.handleEventGracefully(eventToHandle, payment, ex);
226227
}
227228
}
228229
}

services/EventService.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const _ = require('lodash');
1313
const logger = require('../utils/logger');
1414
const gitHubService = require('./GithubService');
1515
const gitlabService = require('./GitlabService');
16+
const models = require('../models');
17+
const dbHelper = require('../utils/db-helper');
1618

1719
const timeoutMapper = {};
1820

@@ -80,6 +82,11 @@ async function handleEventGracefully(event, data, err) {
8082
} else if (event.event === 'copilotPayment.add') {
8183
// comment for copilot payment challenge create failed
8284
comment = 'The copilot payment challenge creation on the Topcoder platform failed. Please contact support to try again';
85+
await dbHelper.remove(models.CopilotPayment, {
86+
id: {eq: data.id}
87+
});
88+
// we dont need to put comment for copilot payment
89+
return;
8390
}
8491
// notify error in git host
8592
if (event.provider === 'github') {

0 commit comments

Comments
 (0)