I use this method in a sidekiq job:
def attach_poster(poster_url,obj)
resp = HTTParty.get(poster_url)
file = Tempfile.new
begin
file.binmode
file.write(resp.body)
file.rewind
obj.poster.attach(io: file, filename: "poster.png")
ensure
file.close
file.unlink
end
end
This only works when I start the job with .perform_inline, like so: ImportJob.perform_inline(poster_url,obj)
When I use .perform_async, the file does not get attached properly which results in a FileNotFoundError. Why is that?
I would like to use perform_async so that the job runs asynchronously from the main process.
I am on Ubuntu 20.04, latest versions of Rails and Sidekiq.