Can Rails ActiveJob be used to enqueue a block of code? -
can rails' new activejob api used enqueue block of code? don't want generate job , move logic there. moves knowledge out of model i'd rather keep there.
let me give example in project i'm working on. little weird it's letting me keep knowledge in model.
# app/models/subscription.rb class subscription < activerecord::base def cancel cancelsubscriptionjob.perform(self) end def cancel_tasks # stuff takes long time end end # app/jobs/cancel_subscription_job.rb class cancelsubscriptionjob < activejob::base def perform(subscription) subscription.cancel_tasks end end i feel i'm going around elbow !@# here. guess argument made cancel_tasks method belongs in job, don't that. want see cancellation tasks in model i've been keeping rest of type of knowledge.
there's argument none of belongs in model in first place, @ point in rails feel people telling me extract , extract , extract until never actual work done.
you theoretically use metaprogramming build subclass on fly, follows activejob spec, think that's more confusion need.
i'd create thin activejob calls model method, wrapper it.
btw there's argument keeping models thin , focused on persistence rather kind of business logic you'd want queue. in case, extracting business logic out of models thing. people can use job classes keep logic in, i'd prefer keep them thin , instead have logic in service classes.
Comments
Post a Comment