Assuming a concern that services multiple controllers, there is an issue when it comes to an ActiveJob, because of the parsing sequence, the behaviour is different from running commands in the console, where one would state include GenericMethods
before executing any of its methods.
module GenericMethods
extend ActiveSupport::Concern
included do
def create_availabililty(days_ahead)
...
end
end
end
class SomeJob < ApplicationJob
queue_as :default
def perform(days_ahead)
create_availabililty(days_ahead)
end
end
placing the include
statement at the start will be called on, at that point in processing time, an inexistent method.
Which raises the case for using a callback. the documentation suggests stating around_perform
with a private method.
Given there is a yield
block, this permits a callback before or after the perform
method. What is not clear, to this observer (and the console behaviour muddies the waters), is whether include GenericMethods
should be called before or after the yield
(i.e. is the method now known to the application and can then be subject to the include before running? or should it be after)
private
def around_cleanup
# Do something before perform
yield
# Do something after perform
end