Skip to content

Commit

Permalink
improved-cron-error-handling (#219)
Browse files Browse the repository at this point in the history
- cron jobs will now catch and log errors instead of silently ignoring them
  • Loading branch information
ndortega authored Sep 21, 2024
1 parent 925bdc6 commit 4ec34b8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/cron.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,12 @@ function startcronjobs(cron::CronContext)
end
# Execute the function if it's time and if we are still running
if ms_to_wait <= 0 && cron.run[]
try
@async func() # for ordinary functions
catch error
@error "ERROR in CRON job { id: $job_id, expr: $expression, name: $name }: " exception=(error, catch_backtrace())
@async begin
try
func() # for ordinary functions
catch error
@error "ERROR in CRON job { id: $job_id, expr: $expression, name: $name }: " exception=(error, catch_backtrace())
end
end
end
end
Expand Down
5 changes: 5 additions & 0 deletions test/cronmanagement.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ end
iterations[] += 1
end

# make sure we can see errors in the logs
@cron "*/3" function()
throw("Here's a custom error")
end

@cron "*/5" function()
iterations[] += 1
end
Expand Down

0 comments on commit 4ec34b8

Please sign in to comment.