Skip to content

Commit

Permalink
Fix webhooks delivery logs always in pending state
Browse files Browse the repository at this point in the history
  • Loading branch information
synzen committed Dec 25, 2024
1 parent cddb44f commit 525b16f
Showing 1 changed file with 39 additions and 35 deletions.
74 changes: 39 additions & 35 deletions services/user-feeds/src/delivery/mediums/discord-medium.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ export class DiscordMediumService implements DeliveryMedium {
);
}

return [await this.deliverArticleToWebhook(article, webhook, details)];
return await this.deliverArticleToWebhook(article, webhook, details);
} else if (channel) {
if (channel.type === "forum") {
return await this.deliverArticleToChannelForum(
Expand All @@ -393,13 +393,7 @@ export class DiscordMediumService implements DeliveryMedium {

const channelId = channel.id;

const res = await this.deliverArticleToChannel(
article,
channelId,
details
);

return [res];
return await this.deliverArticleToChannel(article, channelId, details);
} else {
throw new Error("No channel or webhook specified for Discord medium");
}
Expand Down Expand Up @@ -722,7 +716,7 @@ export class DiscordMediumService implements DeliveryMedium {
article: Article,
channelId: string,
details: DeliverArticleDetails
): Promise<ArticleDeliveryState> {
): Promise<ArticleDeliveryState[]> {
const {
deliverySettings: {
guildId,
Expand All @@ -746,10 +740,12 @@ export class DiscordMediumService implements DeliveryMedium {
components,
});

const deliveryId = generateDeliveryId();
const parentDeliveryId = generateDeliveryId();

const allRecords: ArticleDeliveryState[] = await Promise.all(
bodies.map(async (body, idx) => {
const deliveryId = idx === 0 ? parentDeliveryId : generateDeliveryId();

await Promise.all(
bodies.map((body) =>
this.producer.enqueue(
apiUrl,
{
Expand All @@ -765,17 +761,20 @@ export class DiscordMediumService implements DeliveryMedium {
guildId,
emitDeliveryResult: true,
}
)
)
);

return {
id: deliveryId,
status: ArticleDeliveryStatus.PendingDelivery,
mediumId: details.mediumId,
contentType: ArticleDeliveryContentType.DiscordArticleMessage,
parent: idx === 0 ? undefined : parentDeliveryId,
articleIdHash: article.flattened.idHash,
};
})
);

return {
id: deliveryId,
status: ArticleDeliveryStatus.PendingDelivery,
mediumId: details.mediumId,
contentType: ArticleDeliveryContentType.DiscordArticleMessage,
articleIdHash: article.flattened.idHash,
};
return allRecords;
}

private async deliverArticleToWebhook(
Expand All @@ -794,7 +793,7 @@ export class DiscordMediumService implements DeliveryMedium {
threadId?: string | null;
},
details: DeliverArticleDetails
): Promise<ArticleDeliveryState> {
): Promise<ArticleDeliveryState[]> {
const {
deliverySettings: {
guildId,
Expand Down Expand Up @@ -843,10 +842,12 @@ export class DiscordMediumService implements DeliveryMedium {
}),
}));

const deliveryId = generateDeliveryId();
await Promise.all(
bodies.map((body) =>
this.producer.enqueue(
const parentDeliveryId = generateDeliveryId();
const allRecords: ArticleDeliveryState[] = await Promise.all(
bodies.map(async (body, idx) => {
const deliveryId = idx === 0 ? parentDeliveryId : generateDeliveryId();

await this.producer.enqueue(
apiUrl,
{
method: "POST",
Expand All @@ -861,17 +862,20 @@ export class DiscordMediumService implements DeliveryMedium {
guildId,
emitDeliveryResult: true,
}
)
)
);

return {
id: deliveryId,
status: ArticleDeliveryStatus.PendingDelivery,
mediumId: details.mediumId,
contentType: ArticleDeliveryContentType.DiscordArticleMessage,
articleIdHash: article.flattened.idHash,
parent: idx === 0 ? undefined : parentDeliveryId,
};
})
);

return {
id: generateDeliveryId(),
status: ArticleDeliveryStatus.PendingDelivery,
mediumId: details.mediumId,
contentType: ArticleDeliveryContentType.DiscordArticleMessage,
articleIdHash: article.flattened.idHash,
};
return allRecords;
}

getForumTagsToSend(
Expand Down

0 comments on commit 525b16f

Please sign in to comment.