I have Rails 4.2 running on Unicorn.
I need to call an sh script from my application, but I need my controller to call the SH script and not wait for the SH script to run.
I currently call the sh script with system(@jobCall)
For this I installed the delayed_job gem. How do I run the system(@jobCall)
without waiting for the job to finish?
Full create method code below:
def create
@job = Job.new(job_params)
respond_to do |format|
if @job.save
@jobCall = 'sh /home/some.user/kitchen.sh'
system(@jobCall) ##need to call this and not wait for job to finish
format.html { redirect_to @job, notice: 'Job ran'}
format.json { render :show, status: :created, location: @job }
else
format.html { render :new }
format.json { render json: @job.errors, status: :unprocessable_entity }
end
end
end
I think what you need is to run the job in the background using threads. Although, you may want another way of getting the job result, not render or redirect if you don't need to wait for it to finish.