Skip to content

Commit e7892cd

Browse files
committed
refactor(file-search): key the dispatch window by the instant the gate checked
1 parent 154f1c8 commit e7892cd

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

‎apps/sim/lib/workspace-files/search/enqueue-dispatch.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ const logger = createLogger('WorkspaceFileSearchDispatchEnqueue')
1818
* Starts no dispatcher run when there is nothing to dispatch. A failed check starts one anyway, so
1919
* an unhealthy probe can delay indexing by at most the dispatcher's own failure, never strand it.
2020
*/
21-
async function hasDispatchWork(): Promise<boolean> {
21+
async function hasDispatchWork(now: Date): Promise<boolean> {
2222
try {
23-
return await hasWorkspaceFileSearchDispatchWork(new Date())
23+
return await hasWorkspaceFileSearchDispatchWork(now)
2424
} catch (error) {
2525
logger.warn('Workspace file search dispatch work check failed; dispatching anyway', {
2626
error: getErrorMessage(error),
@@ -34,14 +34,16 @@ async function hasDispatchWork(): Promise<boolean> {
3434
* development-only and detaches from the HTTP response because the local server is long-lived.
3535
*/
3636
export async function enqueueWorkspaceFileSearchDispatch(): Promise<ScheduledPassResult> {
37+
const now = new Date()
3738
return startScheduledPass({
38-
due: await hasDispatchWork(),
39+
due: await hasDispatchWork(now),
3940
triggerAvailable: () => isTriggerDevEnabled,
4041
startInline: () =>
4142
runDetached('workspace-file-search-dispatch', dispatchWorkspaceFileSearchIndexJobs),
4243
trigger: {
4344
taskId: 'workspace-file-search-dispatch',
4445
intervalMs: FILE_SEARCH_DISPATCH_INTERVAL_MS,
46+
at: now,
4547
options: { maxDuration: FILE_SEARCH_DISPATCH_MAX_DURATION_SECONDS, ttl: '5m' },
4648
},
4749
})

0 commit comments

Comments
 (0)