<@U078483LN> I'm running into an issue with ColdBo...
# box-products
c
@lmajano I'm running into an issue with ColdBox 7 scheduled tasks. It seems that when a task fails or errors out, the task never runs again. I have occasional API call issues or SQL deadlock issues. They are usually one-offs and don't justify not running again. How do I prevent the task from stopping completely?
b
Are you catching the error or letting it bubble up?
c
LogBox sends me an email on them, but they are pretty irrelevant. Maybe one or two a day.
So I don’t need to do anything
b
That wasn't what I asked
c
No, I am not catching the error. If it fails, it gets caught up the next time it runs.
@bdw429s
b
Right or wrong, catching the error and not rethrowing it will likely stop your task from dying
Java's scheduled executors have a charming little behavior where unhandled exceptions from inside the thread will cause the thread to die and never run again.
I assume that's what's happening here
I personally think ColdBox should capture these errors itself to prevent this unexcepted behavior (cc/ @lmajano can confirm)
c
@bdw429s I'll look into that for the API errors. On the other hand, the occasional SQL deadlocked transaction could be any single query. That's more of a time-sink to handle all of those. Thanks!
b
@Cavan Vannice To be clear, I'm not suggesting you wrap a bunch of individual bits of code inside your tasks with try/catch. Just do one at the top level to prevent any exceptions from bubbling up to the Java thread
Copy code
task( "my-task" )
    .call( () => {
       try {
         yourService.yourTaskLogic();
       } catch( any e ) {
          // Error logging here so you still know about the errors.
       }
    } )
    .everyHour();
c
Ah, that makes more sense. I'll give that a try!
@bdw429s
l
All errors on scheduled tasks are trapped
FYI
and sent to the error logs and logbox if in ColdBox
so they are always trapped
c
@lmajano Ok, thanks.