bcquality/microsoft/knowledge/performance/job-queue-external-effects-must-be-idempotent.good.al
demiliani bb3398610e Merge branch 'main' of https://github.com/demiliani/BCQuality into jobqueue
# Conflicts:
#	microsoft/knowledge/performance/job-queue-category-code-serializes-conflicting-jobs.bad.al
#	microsoft/knowledge/performance/job-queue-category-code-serializes-conflicting-jobs.good.al
#	microsoft/knowledge/performance/job-queue-category-code-serializes-conflicting-jobs.md
#	microsoft/knowledge/performance/job-queue-external-effects-must-be-idempotent.bad.al
#	microsoft/knowledge/performance/job-queue-external-effects-must-be-idempotent.good.al
#	microsoft/knowledge/performance/job-queue-external-effects-must-be-idempotent.md
#	microsoft/knowledge/performance/job-queue-handlers-must-not-require-ui.bad.al
#	microsoft/knowledge/performance/job-queue-handlers-must-not-require-ui.good.al
#	microsoft/knowledge/performance/job-queue-handlers-must-not-require-ui.md
#	microsoft/knowledge/performance/job-queue-handlers-must-propagate-failures.bad.al
#	microsoft/knowledge/performance/job-queue-handlers-must-propagate-failures.good.al
#	microsoft/knowledge/performance/job-queue-handlers-must-propagate-failures.md
#	microsoft/knowledge/performance/job-queue-on-hold-does-not-stop-running-work.bad.al
#	microsoft/knowledge/performance/job-queue-on-hold-does-not-stop-running-work.good.al
#	microsoft/knowledge/performance/job-queue-on-hold-does-not-stop-running-work.md
#	microsoft/knowledge/performance/store-scheduled-task-id-to-avoid-duplicate-tasks.bad.al
#	microsoft/knowledge/performance/store-scheduled-task-id-to-avoid-duplicate-tasks.good.al
#	microsoft/knowledge/performance/store-scheduled-task-id-to-avoid-duplicate-tasks.md
2026-09-08 17:02:26 +02:00

65 lines
No EOL
1.7 KiB
AL

table 50112 "Queued Export Good"
{
DataClassification = CustomerContent;
fields
{
field(1; "Entry No."; Integer)
{
AutoIncrement = true;
}
field(2; Payload; Text[250])
{
}
}
keys
{
key(PK; "Entry No.")
{
Clustered = true;
}
}
}
codeunit 50112 "Queued Export Worker Good"
{
TableNo = "Job Queue Entry";
trigger OnRun()
var
QueuedExport: Record "Queued Export Good";
Client: HttpClient;
Content: HttpContent;
ContentHeaders: HttpHeaders;
JsonPayload: JsonObject;
RequestBody: Text;
Response: HttpResponseMessage;
begin
if not QueuedExport.FindFirst() then
exit;
JsonPayload.Add('idempotencyKey', Format(QueuedExport.SystemId));
JsonPayload.Add('payload', QueuedExport.Payload);
JsonPayload.WriteTo(RequestBody);
Content.WriteFrom(RequestBody);
Content.GetHeaders(ContentHeaders);
ContentHeaders.Clear();
ContentHeaders.Add('Content-Type', 'application/json');
Client.Post('https://example.local/exports', Content, Response);
if not Response.IsSuccessStatusCode() then
Error('Export failed with HTTP status %1.', Response.HttpStatusCode());
// The external service must atomically create a record only when idempotencyKey
// does not exist. When the key already exists, it must return the existing record
// without repeating the side effect.
UpdateLocalStatus();
QueuedExport.Delete();
end;
local procedure UpdateLocalStatus()
begin
end;
}