Skip to content

fix(queue): widen upsertJobScheduler id parameter to free string - #4107

Open
mohanrajvenkatesan23-04 wants to merge 1 commit into
taskforcesh:masterfrom
mohanrajvenkatesan23-04:fix/issue-3937-scheduler-id-type
Open

fix(queue): widen upsertJobScheduler id parameter to free string#4107
mohanrajvenkatesan23-04 wants to merge 1 commit into
taskforcesh:masterfrom
mohanrajvenkatesan23-04:fix/issue-3937-scheduler-id-type

Conversation

@mohanrajvenkatesan23-04

@mohanrajvenkatesan23-04 mohanrajvenkatesan23-04 commented Apr 26, 2026

Copy link
Copy Markdown
Contributor

Port Impact Checklist

  • Python – does this change need to be ported or documented in the Python library?
  • Elixir – does this change need to be ported or documented in the Elixir library?
  • PHP – does this change need to be ported or documented in the PHP library?

Why

Fixes #3937.

Queue.upsertJobScheduler's first parameter jobSchedulerId was typed as the queue's NameType generic. This created a hard coupling between the scheduler's unique identifier and the union of job names the queue produces. In real distributed setups the scheduler id is typically a per-instance UUID (inst_12345, a database row id, etc.) that has nothing to do with the job-name literal union, so any typed queue rejected the call at compile time:

type MyJobs = Job<any, any, 'generate-report'> | Job<any, any, 'send-email'>;
const queue = new Queue<MyJobs>('q');

queue.upsertJobScheduler(
  'inst_12345',                                  // ❌ TS error before this PR
  { pattern: '0 * * * *' },
  { name: 'generate-report', data: { foo: 'bar' } },
);

The underlying JobScheduler.upsertJobScheduler already types the id correctly as string (with the job name as a separate N extends string = string generic) — the bug was a leak in the public Queue wrapper.

How

  • src/classes/queue.ts: change the parameter type from jobSchedulerId: NameType to jobSchedulerId: string. This matches the underlying JobScheduler.upsertJobScheduler signature.
  • The fallback jobTemplate?.name ?? jobSchedulerId is now jobTemplate?.name ?? (jobSchedulerId as NameType). The cast is intentional and preserves the existing runtime behaviour: when the caller does not supply a template name, the resulting job's name is still the scheduler id. Users who want strict type safety on the produced job's name should pass jobTemplate.name explicitly (which the issue's example already does).
  • No changes to JobScheduler itself — the underlying API was already correct.

Additional Notes (Optional)

  • New regression test in tests/job_scheduler.test.ts (when the queue has a constrained NameType) that builds a Queue<unknown, unknown, 'generate-report' | 'send-email'> and calls upsertJobScheduler with a free-string id. Before the fix this fails to compile; after, it compiles and the runtime asserts the resulting job's name is 'generate-report'.
  • No public API behaviour change — only the type signature is widened. Existing callers keep compiling.
  • Scope is purely Node.js / TypeScript types; no Python / Elixir / PHP port work needed.

@manast
manast requested review from Copilot and roggervalf and removed request for Copilot July 15, 2026 18:10
The first parameter of Queue.upsertJobScheduler was typed as the
queue's NameType generic, which incorrectly coupled the scheduler's
unique identifier to the union of job names. Distributed setups
typically use a per-instance UUID for the scheduler id while the job
names remain a fixed literal union, so typed queues rejected any
non-literal scheduler id at compile time.

The underlying JobScheduler.upsertJobScheduler already types the id
as `string`; this aligns the public Queue API with that, and casts
the no-name fallback to NameType so the existing runtime behaviour
(falling back to the scheduler id when no template name is given) is
preserved.

Fixes taskforcesh#3937
@roggervalf
roggervalf force-pushed the fix/issue-3937-scheduler-id-type branch from 545c89b to 696af47 Compare July 16, 2026 03:29
@manast

manast commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: upsertJobScheduler ID parameter is incorrectly constrained to NameType

2 participants