Transactional background jobs with grails

227 Views Asked by At

Is it possible to enforce transactionality in a background job from jesque from grails?

I'm using jesque-grails plugin where I can inject other services including GORM ... may I mark the job as @Transaction and expect the payload to be executed in a isolated transaction with rollback on failure?

2

There are 2 best solutions below

0
On BEST ANSWER

After trying i found the answer is yes. You can simply mark the job as @Transactional and it should work as expected.

0
On

@Transactional works on controllers and services (though it's use on controller actions is not generally recommended). I don't know if it will work on jesque jobs, but it should be pretty easy to find out, i.e. save something, then throw a RuntimeException and see if the saved data is rolled back.

If you can't annotate your method with @Transactional you could instead wrap the method in withTransaction