-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
fix: keep Temporal workflow when a scheduled post is edited without a time change #1690
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
31e8b94
b55d702
61df6d7
043e2da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -900,10 +900,22 @@ export class PostsService { | |
| content: removeLinks ? stripLinks(updateContent[i]) : updateContent[i], | ||
| })); | ||
|
|
||
| const scheduledDate = | ||
| body.type === 'now' | ||
| ? dayjs().format('YYYY-MM-DDTHH:mm:00') | ||
| : body.date; | ||
|
|
||
| // Grab the current publish time BEFORE the upsert overwrites it, so we | ||
| // can tell (below) whether an edit actually moved the post's time. | ||
| const existingRootId = post.value?.[0]?.id; | ||
| const existingRoot = existingRootId | ||
| ? await this._postRepository.getPostById(existingRootId, orgId) | ||
| : null; | ||
|
|
||
|
Comment on lines
+910
to
+914
This comment was marked as outdated.
Sorry, something went wrong.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Partially right — normal group edits update rows in place via upsert (ids preserved), so no new records are created and the existing workflow stays keyed to the same root; and when records genuinely are recreated, existingRoot is null so the skip can't fire. The real gap was an edit that promotes a child row to root (thread head removed/reordered) — fixed in 043e2da by requiring existingRoot to have no parentPostId. |
||
| const { posts } = await this._postRepository.createOrUpdatePost( | ||
| body.type, | ||
| orgId, | ||
| body.type === 'now' ? dayjs().format('YYYY-MM-DDTHH:mm:00') : body.date, | ||
| scheduledDate, | ||
| post, | ||
| body.tags, | ||
| creationMethod, | ||
|
|
@@ -914,7 +926,24 @@ export class PostsService { | |
| return [] as any[]; | ||
| } | ||
|
|
||
| if (body.type !== 'update') { | ||
| // Only (re)start the Temporal workflow when it's actually needed: a new | ||
| // post, or a scheduled post whose publish time changed. Editing a queued | ||
| // post without moving its time keeps the existing workflow - content and | ||
| // settings are re-read from the DB at publish time, so a restart (which | ||
| // would terminate + recreate the workflow) is unnecessary churn. | ||
| // Only a 'schedule' save may skip: 'draft'/'now' saves must still go | ||
| // through startWorkflow so the old run is terminated. The existing row | ||
| // must also BE the root: if the edit promoted a child row (thread head | ||
| // removed/reordered), the workflow is keyed to the old root, which gets | ||
| // soft-deleted - the new root needs its own workflow. | ||
| const publishTimeUnchanged = | ||
| body.type === 'schedule' && | ||
| !!existingRoot && | ||
| !existingRoot.parentPostId && | ||
| existingRoot.state === 'QUEUE' && | ||
| dayjs(existingRoot.publishDate).isSame(dayjs(scheduledDate), 'minute'); | ||
|
|
||
| if (body.type !== 'update' && !publishTimeUnchanged) { | ||
|
Comment on lines
+939
to
+946
This comment was marked as outdated.
Sorry, something went wrong.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in a followup commit |
||
| this.startWorkflow( | ||
| post.settings.__type.split('-')[0].toLowerCase(), | ||
| posts[0].id, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: On non-UTC servers, creating a
scheduledDatewithdayjs().format()and parsing it withdayjs.utc()causes an incorrect time comparison for posts withtype: 'now'.Severity: MEDIUM
Suggested Fix
Ensure timezone consistency. When generating the
scheduledDatefortype === 'now', usedayjs.utc()to create a UTC-based time string. Replacedayjs().format('YYYY-MM-DDTHH:mm:00')withdayjs.utc().format('YYYY-MM-DDTHH:mm:00')to align the generated time with the UTC-based comparison logic used later.Prompt for AI Agent
Did we get this right? 👍 / 👎 to inform future reviews.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed with the new commit