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

Commit c2d213b

Browse files
committed
Merge branch 'develop' of github.com:topcoder-platform/topcoder-x-processor into develop
2 parents d02e1c8 + 7c8518c commit c2d213b

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

services/IssueService.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ const eventService = require('./EventService');
2626

2727
const md = new MarkdownIt();
2828

29+
// A variable to store issue creation lock to prevent duplicate creation process.
30+
// The key is `${provider}-${repositoryId}-${number}`. The value is True.
31+
const issueCreationLock = {};
32+
2933
/**
3034
* Generate the contest url, given the challenge id
3135
* @param {String} challengeId The id of the challenge in topcoder
@@ -555,6 +559,13 @@ async function handleIssueCreate(event, issue, forceAssign = false) {
555559
return;
556560
}
557561

562+
const creationLockKey = `${issue.provider}-${issue.repositoryId}-${issue.number}`;
563+
if (issueCreationLock[creationLockKey]) {
564+
throw new Error(
565+
`Issue ${creationLockKey} is creating.`);
566+
}
567+
issueCreationLock[creationLockKey] = true;
568+
558569
// create issue with challenge creation pending
559570
const issueObject = _.assign({}, _.omit(issue, 'assignee'), {
560571
id: helper.generateIdentifier(),
@@ -594,6 +605,7 @@ async function handleIssueCreate(event, issue, forceAssign = false) {
594605
logger.error(`Challenge creation failure: ${e}`);
595606
await dbHelper.removeIssue(models.Issue, issue.repositoryId, issue.number, issue.provider);
596607
await eventService.handleEventGracefully(event, issue, e);
608+
delete issueCreationLock[creationLockKey];
597609
return;
598610
}
599611

@@ -610,6 +622,7 @@ async function handleIssueCreate(event, issue, forceAssign = false) {
610622
await handleIssueAssignment(event, issue, true);
611623
}
612624
}
625+
delete issueCreationLock[creationLockKey];
613626
logger.debug(`new challenge created with id ${issue.challengeId} for issue ${issue.number}`);
614627
}
615628

utils/topcoder-api-helper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ async function getChallengeById(id) {
297297
* @param {Number} winnerId the winner id
298298
*/
299299
async function closeChallenge(id, winnerId) {
300-
const apiKey = await getAccessToken();
300+
const apiKey = await getM2Mtoken();
301301
logger.debug(`Closing challenge ${id}`);
302302
try {
303303
let basePath = challengesClient.basePath;

0 commit comments

Comments
 (0)