Skip to content

Commit 2b3c0c9

Browse files
author
Christian
committed
Checking if the edit has already occurred
1 parent 20c10e7 commit 2b3c0c9

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/ServiceControl/MessageFailures/Api/EditFailedMessagesController.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ public async Task<IActionResult> Edit(string failedMessageId, [FromBody] EditMes
3535
return NotFound();
3636
}
3737

38+
//HINT: This validation is the first one because we want to minimize the chance of two users concurrently execute an edit-retry.
39+
var editManager = await store.CreateEditFailedMessageManager();
40+
var editId = await editManager.GetCurrentEditingMessageId(failedMessageId);
41+
if (editId != null)
42+
{
43+
logger.LogWarning("Cannot edit message {FailedMessageId} because it has already been edited", failedMessageId);
44+
// We return HTTP 200 even though the edit is being ignored. This is to keep the compatibility with older versions of ServicePulse.
45+
// Newer ServicePulse versions (starting with x.x) will handle the response's payload accordingly.
46+
return Ok(new { EditIgnored = true });
47+
}
48+
3849
var failedMessage = await store.ErrorBy(failedMessageId);
3950

4051
if (failedMessage == null)
@@ -45,8 +56,8 @@ public async Task<IActionResult> Edit(string failedMessageId, [FromBody] EditMes
4556

4657
//WARN
4758
/*
48-
* failedMessage.ProcessingAttempts.Last() return the lat retry attempt.
49-
* In theory between teh time someone edits a failed message and retry it someone else
59+
* failedMessage.ProcessingAttempts.Last() return the last retry attempt.
60+
* In theory between the time someone edits a failed message and retry it someone else
5061
* could have retried the same message without editing. If this is the case "Last()" is
5162
* not anymore the same message.
5263
* Instead of using Last() it's probably better to select the processing attempt by looking for
@@ -74,7 +85,7 @@ await session.SendLocal(new EditAndSend
7485
NewHeaders = edit.MessageHeaders
7586
});
7687

77-
return Accepted();
88+
return Accepted(new { EditIgnored = false });
7889
}
7990

8091

0 commit comments

Comments
 (0)