Skip to content

πŸ“¨ The ultimate agentic social media scheduling tool πŸ€–

fix: address code review findings on the pending-post workflow

Nevo David9944a5fcd0cb
diff --git a/apps/orchestrator/src/workflows/post-workflows/post.workflow.v1.0.6.ts b/apps/orchestrator/src/workflows/post-workflows/post.workflow.v1.0.6.ts
index 6491c5f60..cef3d1258 100644
--- a/apps/orchestrator/src/workflows/post-workflows/post.workflow.v1.0.6.ts
+++ b/apps/orchestrator/src/workflows/post-workflows/post.workflow.v1.0.6.ts
@@ -77,8 +77,10 @@ const poke = defineSignal('poke');
const iterate = Array.from({ length: 5 });
-// ~15 minutes at 20s interval (longer than the old in-activity loop, timers are free)
-const maxPendingChecks = 45;
+// ~30 minutes at 20s interval (longer than the old in-activity loop, timers are
+// free). Multi-item flows (stories, chunked uploads) consume several checks per
+// item, so the budget must cover the largest realistic post, not one poll cycle.
+const maxPendingChecks = 90;
export async function postWorkflowV106({
taskQueue,
diff --git a/libraries/nestjs-libraries/src/integrations/social/instagram.provider.ts b/libraries/nestjs-libraries/src/integrations/social/instagram.provider.ts
index caf40db79..1ab4c0915 100644
--- a/libraries/nestjs-libraries/src/integrations/social/instagram.provider.ts
+++ b/libraries/nestjs-libraries/src/integrations/social/instagram.provider.ts
@@ -654,7 +654,6 @@ export class InstagramProvider
): Promise<PostResponse[]> {
const [accessToken] = token.split('___');
const [firstPost] = postDetails;
- console.log('in progress', id);
const isStory = firstPost.settings.post_type === 'story';
const isTrialReel = this.assetBoolean(firstPost.settings.is_trial_reel);
const medias = await Promise.all(
diff --git a/libraries/nestjs-libraries/src/integrations/social/tiktok.provider.ts b/libraries/nestjs-libraries/src/integrations/social/tiktok.provider.ts
index 1f70bcec1..b805baa2c 100644
--- a/libraries/nestjs-libraries/src/integrations/social/tiktok.provider.ts
+++ b/libraries/nestjs-libraries/src/integrations/social/tiktok.provider.ts
@@ -465,16 +465,16 @@ export class TiktokProvider extends SocialAbstract implements SocialProvider {
}
if (status === 'PUBLISH_COMPLETE') {
+ // an empty array is truthy, so index it once and branch on the value
+ const publicPostId = publicaly_available_post_id?.[0];
+
return {
status: 'completed',
- releaseURL: !publicaly_available_post_id
+ releaseURL: !publicPostId
? `https://www.tiktok.com/@${integration.profile}`
- : `https://www.tiktok.com/@${integration.profile}/video/` +
- publicaly_available_post_id,
+ : `https://www.tiktok.com/@${integration.profile}/video/${publicPostId}`,
// TikTok returns the id as a number, releaseId in the db is a string
- postId: !publicaly_available_post_id
- ? pendingData.publishId
- : String(publicaly_available_post_id?.[0]),
+ postId: !publicPostId ? pendingData.publishId : String(publicPostId),
};
}
@@ -710,6 +710,18 @@ export class TiktokProvider extends SocialAbstract implements SocialProvider {
const response = await fetch(path, {
headers: { Range: `bytes=${start}-${end}` },
});
+
+ // A store that ignores Range (200 with the full file) or answers with an
+ // error page would corrupt the upload at this offset.
+ if (response.status !== 206) {
+ throw new BadBody(
+ 'tiktok-error-upload',
+ '{}',
+ '{}',
+ 'The media storage did not return the requested byte range, please try again'
+ );
+ }
+
return response.body;
}
@@ -893,7 +905,7 @@ export class TiktokProvider extends SocialAbstract implements SocialProvider {
const started = Date.now();
- for (const i of Array(27).keys()) {
+ for (const _ of Array(27).keys()) {
// ~9 minutes at 20s interval
const check = await this.checkPostStatus(
accessToken,
diff --git a/libraries/nestjs-libraries/src/integrations/social/youtube.provider.ts b/libraries/nestjs-libraries/src/integrations/social/youtube.provider.ts
index eeaf17b87..f0691ab04 100644
--- a/libraries/nestjs-libraries/src/integrations/social/youtube.provider.ts
+++ b/libraries/nestjs-libraries/src/integrations/social/youtube.provider.ts
@@ -453,6 +453,18 @@ export class YoutubeProvider extends SocialAbstract implements SocialProvider {
const response = await fetch(path, {
headers: { Range: `bytes=${start}-${end}` },
});
+
+ // A store that ignores Range (200 with the full file) or answers with an
+ // error page would corrupt the upload at this offset.
+ if (response.status !== 206) {
+ throw new BadBody(
+ this.identifier,
+ '{}',
+ '{}',
+ 'The media storage did not return the requested byte range, please try again'
+ );
+ }
+
return response.body;
}
@@ -810,10 +822,13 @@ export class YoutubeProvider extends SocialAbstract implements SocialProvider {
// eslint-disable-next-line no-constant-condition
while (true) {
// Cap below the 10-minute activity timeout of the old workflows using
- // this method: failing here is safe (no video exists until the upload
- // completes and the abandoned session just expires), timing the
- // activity out is not.
- if (Date.now() - started > 4.5 * 60 * 1000) {
+ // this method, leaving room for one more full upload batch: failing here
+ // is safe (no video exists until the upload completes and the abandoned
+ // session just expires), timing the activity out is not.
+ if (
+ Date.now() - started >
+ 8 * 60 * 1000 - YoutubeProvider.YOUTUBE_UPLOAD_BATCH_MS
+ ) {
throw new BadBody(
this.identifier,
'{}',