Skip to content

Deprecate perform/1 in favor of perform/2 #45

@chrismccord

Description

@chrismccord

Thanks for this fantastic library!

Currently, users expect the job args to be passed to perform/1, and when they need access to the %Job{}, they define a new perform/1 clause which matches on the job. This works because Oban injects:

      def perform(%Job{args: args}), do: perform(args)
      def perform(args) when is_map(args), do: :ok

While this works with very little code injection, it's non obvious to users how to reach the Job struct when needed, and non obvious that once they define their own clause that matches the struct, they may invalidate other previously valid perform/1 clauses depending on what they are doing. Instead of the argument type dance, I propose we introduce perform/2 which receives the job struct, followed by arguments. For the general use case, this still looks quite nice:

def perform(_job, %{some: arg}) do

This way it's clear what is called and when, and also makes the job metadata instantly accessible once needed. I think the throwaway arg is a very reasonable tradeoff for the times the job info isn't needed. Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions