I would like to pass on the request params so that I can execute it on the delayed_job as follows:
ObserveJob.perform_later(request)
but the error is always ActiveJob::SerializationError: Unsupported argument type: ActionDispatch::Request
Is there a way to pass on this built-in request params in rails so it will execute properly using delayed_job?
There can many ways one could be:
Delayed::Job.enqueue(Abc.new(param1, param2, queue: "Update Derive")
Delayed job will be like:
class Abc < Struct.new(:param1, :param2)
def perform
sum = param1 + param2
...
end
end
Instead of passing the whole request
object – which is quite big and complex – only pass the attributes you actually need to the job. This has several advantages:
request
in your question, are hard to serialize or might not even support serialization at all. I would change the perform
method to
def perform(path:, referer:, url: remote_ip:, user_agent:, location:)
# ...
end
and call it like this:
ObserveJob.perform_later(
path: request.path,
referer: request.referer,
url: request.url,
remote_ip: request.remote_ip,
user_agent: request.user_agent,
location: request.location
)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.