简体   繁体   中英

Transactional background jobs with grails

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?

@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, ie 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM