Skip to main content

The ability to attach metadata when creating a schedule

When creating a schedule using the SDK you can set an externalId

const createdSchedule = await schedules.create({
  //The id of the scheduled task you want to attach to.
  task: firstScheduledTask.id,
  //The schedule in cron format.
  cron: "0 0 * * *",
  // Optional, it defaults to "UTC". In IANA format, e.g. "America/New_York".
  // In this case, the task will run at midnight every day in New York time.
  // If you specify a timezone it will automatically work with daylight saving time.
  timezone: "America/New_York",
  //Optionally, you can specify your own IDs (like a user ID) and then use it inside the run function of your task.
  //This allows you to have per-user cron tasks.
  externalId: "user_123456",
  //You can only create one schedule with this key.
  //If you use it twice, the second call will update the schedule.
  //This is useful because you don't want to create duplicate schedules for a user.
  deduplicationKey: "user_123456-todo_reminder",
});


You can use this to then look up data in the run using the externalId.

But it would also be useful to be able to attach metadata to a scheduled and then get that data inside the run. The metadata would probably be a Record<string, string | number | boolean> type.

6 comments

Comments6

  • transitcal .com

    •

    Feb 11, 2025

    +1 to this again!

  • Dimitar Stoykov

    •

    Jan 14, 2025

    This, as well as listing schedules by externalId, would be great. Currently, there is no way to retrieve a schedule if you don’t persist the scheduleId.

  • transitcal .com

    •

    Sep 24, 2024

    Same I want my scheduled tasks to have tags but I need to be able to pass it when i create the schedule

  • Anonymous User

    •

    Jul 24, 2024

    Thks a lot for this feature, what a nice job !

  • Anonymous User

    •

    Jul 23, 2024

    Nice feature

  • Anonymous User

    •

    Jul 23, 2024

    Great feature to implement, in many cases we need to add metadata to our functions in schedules.task() to perform some useful unique tasks.