swift run Run jobs --scheduled only works with using .at()
khoogheem opened this issue · 11 comments
If you schedule a job using at with a specific date then the scheduled works.. however if you try and setup a job using something like .everySecond()
it never process the jobs
works
public func configure(_ app: Application) throws {
app.jobs.schedule(TestJob()).at(Date(rfc1123: "Sat, 04 Jan 2020 16:47:40 GMT")!)
try app.jobs.use(.redis(url: "redis://127.0.0.1:6379"))
}
Doesn't work
public func configure(_ app: Application) throws {
app.jobs.schedule(TestJob()).everySecond()
try app.jobs.use(.redis(url: "redis://127.0.0.1:6379"))
}
job is just a simple print
struct TestJob: ScheduledJob {
func run(context: JobContext) -> EventLoopFuture<Void> {
print("Job has run \(context)")
return context.eventLoop.makeSucceededFuture(Void())
}
}
if I make the change to ScheduleBuilder:
public func everySecond() {
self.second = 1
}
and put in a breakpoint in the nextDate(current
function I can get it to run once.. but not repeated
The other part here in doing some testing
if I use app.jobs.schedule(TestJob()).minutely()
it does not work.
however this does app.jobs.schedule(TestJob()).minutely().at(0)
On this note, I cant get the .schedule to work at all
app.jobs.schedule(SayHi()).everySecond()
app.jobs.schedule(SayHi()).at(Date().addingTimeInterval(5))
app.jobs.schedule(SayHi()).at(Date(rfc1123: "Sat, 12 Jan 2020 11:05:00 AEST") ?? Date())
Nothing happens
@idi888 Just checking that you're actually running the jobs worker?
@mcdappdev I thought I was, I registered the with the redis driver
When i looked into it, it looked like I was missing something becuase the JobsCommand.run was never running
Can you point me to a gist/something
Sure, checkout the docs here: vapor/docs#389
(Make sure to read the ones in the 4.0 folder)
@mcdappdev Thanks I got it
The fix for the everySecond() is simply-ish (might want to rename milliseconds to nanoseconds to keep it inline with DateComponents)
You are not taking into account the milliseconds so the DateComponents is empty so it can not create a nextDate()
if let milliseconds = millisecond {
components.nanosecond = milliseconds
}
@idi888 where are you saying that code should go?
Thanks much @adirburke, it's fixed here: #58
No worries. Happy to help!