mosquito-cr / mosquito

A background task runner for crystal applications supporting periodic (CRON) and manually queued jobs
MIT License
227 stars 24 forks source link

Using multiple params #27

Closed jwoertink closed 4 years ago

jwoertink commented 5 years ago

I guess this isn't a thing? I'm assuming I have to make a special object and do my own custom serialization? If that's the case, then there may need to be a better error message for this.

class AfterLoginWorker < Mosquito::QueuedJob
  params member_id : String
  params ip : String

  def perform
  end
end
web    | no argument named 'member_id'
web    | Matches are:
web    |  - AfterLoginWorker.new(ip : String)
web    |  - AfterLoginWorker.new() (trying this one)
jwoertink commented 5 years ago

If this is something you'd like to support, I can submit a PR for it.

robacarp commented 5 years ago

Perhaps it's counter intuitive, but you pass all the parameters you want into the same macro. This avoids depending on the finished macro hook.

class AfterLoginWorker < Mosquito::QueuedJob
  params(member_id : String, ip : String)

  def perform
  # ...
  end
end
jwoertink commented 5 years ago

Ah. Ok. I'll give that a shot.

jwoertink commented 5 years ago

Alright, this works how I would expect. Cleaned up my code. I see you added the doc tag, so that's good 👍 Thanks!

robacarp commented 4 years ago

Documented in the wiki now: https://github.com/robacarp/mosquito/wiki/Job-Parameters