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

Copilot payment retry. #22

Merged
merged 1 commit into from
Nov 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions services/CopilotPaymentService.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ async function _checkAndReSchedule(event, payment) {
// reschedule
setTimeout(async () => {
const kafka = require('../utils/kafka'); // eslint-disable-line
await kafka.send(JSON.stringify(event));
const eventToHandle = _.omit(event, ['project']);
await kafka.send(JSON.stringify(eventToHandle));
logger.debug('The event is scheduled for retry');
}, config.RETRY_INTERVAL);
return true;
Expand Down Expand Up @@ -218,11 +219,11 @@ async function handlePaymentAdd(event, payment) {

logger.debug(`challenge ${challengeId} has been activated!`);
} catch (ex) {
await dbHelper.remove(models.CopilotPayment, {
id: {eq: payment.id}
await dbHelper.update(models.CopilotPayment, payment.id, {
status: 'challenge_creation_retried'
});

await eventService.handleEventGracefully(event, payment, ex);
const eventToHandle = _.omit(event, ['project']);
await eventService.handleEventGracefully(eventToHandle, payment, ex);
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions services/EventService.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const _ = require('lodash');
const logger = require('../utils/logger');
const gitHubService = require('./GithubService');
const gitlabService = require('./GitlabService');
const models = require('../models');
const dbHelper = require('../utils/db-helper');

const timeoutMapper = {};

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