Proposed Rule Name: Queueable Should Attach Finalizer
Proposed Category: Best Practices
Description: We want to warn the author of Apex whenever they write a class implementing the Queueable
interface and they fail to attach a Finalizer
. We should explain that the lack of a Finalizer
provides no handling capabilities should the Queueable
action fail.
Code Sample:
// Improper code, does not call `System.attachFinalizer` within the `execute` method. public class UserUpdater implements Queueable { private List<User> usersToUpdate; public UserUpdater(List<User> usersToUpdate) { this.usersToUpdate = usersToUpdate; } public void execute(QueueableContext context) { update usersToUpdate; } } // Properly attaches a `Finalizer` public class UserUpdater implements Queueable, Finalizer { private List<User> usersToUpdate; public UserUpdater(List<User> usersToUpdate) { this.usersToUpdate = usersToUpdate; } public void execute(QueueableContext context) { System.attachFinalizer(this); update usersToUpdate; } public void execute(FinalizerContext ctx) { if (ctx.getResult() == ParentJobResult.SUCCESS) { // Handle success } else { // Handle failure } } }
Possible Properties:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4