vapor / queues

A queue system for Vapor.
MIT License
169 stars 41 forks source link

Add Timezone Support for ScheduleBuilder #138

Open vamsii777 opened 2 days ago

vamsii777 commented 2 days ago

There are two main ways to set the timezone for scheduling jobs:

  1. Using the in method
    
    // Using full timezone identifier
    app.queues.schedule(Cleanup()).in(timezone: "America/New_York").daily().(.midnight)

// Using timezone abbreviation app.queues.schedule(Cleanup()).in(timezone: "EST").daily().(.midnight)

2. Using `timezone` parameter in time methods
```swift
// Daily schedule with timezone
app.queues.schedule(Cleanup()).daily().at("15:30", timezone: "Europe/London")

// Using 24-hour format
app.queues.schedule(Cleanup()).daily().at(15, 30, timezone: "Asia/Tokyo")

// Using 12-hour format with AM/PM
app.queues.schedule(Cleanup()).daily().at(3, 30, .pm, timezone: "Australia/Sydney")
grahamburgsma commented 2 days ago

This seems like duplicated configuration as you can already achieve this using:

let calendar = Calendar.current
calendar.timeZone = TimeZone(identifier: "America/New_York")!

app.queues.schedule(Cleanup())
  .using(calendar)
  ...
vamsii777 commented 1 day ago

This seems like duplicated configuration as you can already achieve this using:

let calendar = Calendar.current
calendar.timeZone = TimeZone(identifier: "America/New_York")!

app.queues.schedule(Cleanup())
  .using(calendar)
  ...

Thank you for the feedback @grahamburgsma! While .using(calendar) works, .in(timezone:) simplifies the API and improves developer experience by directly supporting timezone specification in the scheduling step.

API Consistency The proposed .in(timezone:) modifier follows existing builder pattern and provides a more intuitive API that aligns with how developers think about scheduling across timezones.

app.queues.schedule(Cleanup())
.in(timezone: "America/New_York")
.daily()
.at("9:00am")

Developer Experience While .using(calendar) works, it requires:

This approach avoids the need to configure a Calendar, making the code cleaner and more intuitive. Thanks again for sharing your thoughts!