oban v2.7.0 Release Notes

Release Date: 2021-05-25 // almost 3 years ago
  • ๐Ÿ”Œ Pluggable Notifier

    The PubSub functionality Oban relies on for starting, stopping, scaling, and pausing queues is now pluggable. The previous notifier was hard-coded to use Postgres for PubSub via LISTEN/NOTIFY. Unfortunately, LISTEN/NOTIFY doesn't work for PG Bouncer in "Transaction Mode." While relatively few users run in "Transaction Mode," it is increasingly common and deserved a work-around.

    0๏ธโƒฃ Oban.Notifier defines a minimal behaviour and Oban ships with a default implementation, Oban.PostgresNotifier, based on the old LISTEN/NOTIFY ๐Ÿ”ง module. You can specify a different notifier in your Oban configuration:

    config :my_app, Oban,
      notifier: MyApp.CustomNotifier,
      repo: MyApp.Repo,
      ...
    

    An alternate [pg/pg2 based notifier][pgn] is available in Oban Pro.

    Replacing Opts on Unique Conflict

    โšก๏ธ The replace_args option for updating args on unique conflict is replaced with โšก๏ธ a highly flexible replace option. Using replace, you can update any job field when there is a conflict. Replace works for any of the following fields: โฑ args, max_attempts, meta, priority, queue, scheduled_at, tags, ๐Ÿ‘ท worker.

    For example, to change the priority to 0 and increase max_attempts to 5 when there is a conflict:

    BusinessWorker.new(
      args,
      max_attempts: 5,
      priority: 0,
      replace: [:max_attempts, :priority]
    )
    

    โฑ Another example is bumping the scheduled time to 1 second in the future on โฑ conflict. Either scheduled_at or schedule_in values will work, but the โฑ replace option is always scheduled_at.

    UrgentWorker.new(args, schedule_in: 1, replace: [:scheduled_at])
    

    โž• Added

    • ๐Ÿ‘ท [Oban.Job] A new conflict? field indicates whether a unique job conflicted with an existing job on insert.

    • [Oban.Telemetry] Always populate the unsaved_error field for error or discard events. Previously, the field was empty for discard events.

    • ๐Ÿ‘ท [Oban.Queue.Engine] Define a cancel_job/2 callback in the engine and move cancellation from the query module to the BasicEngine.

    ๐Ÿ”„ Changed

    • ๐Ÿ”จ [Oban.Testing] Thanks to a slight refactoring, the perform_job/3 helper now emits the same telemetry events that you'd have in production. The refactoring also exposed and fixed an inconsistency around invalid snooze handlers.

    • โœ… [Oban.Testing] Expose Testing.all_enqueued/0, an alternate clause that doesn't require any options. This new clause makes it possible to check for any enqueued jobs without filters.

    • ๐Ÿ”Œ [Oban.Plugins.Stager] Limit the number of jobs staged at one time to prevent timeout errors while staging a massive number of jobs.

    ๐Ÿ›  Fixed

    • [Oban.Repo] Respect ongoing transactions when using get_dynamic_repo. Prior to this fix, calls that use Oban.Repo, such as Oban.insert/2, could use a different repo than the one used in the current transaction.