2

I am having trouble finding the gem/solution I need to solve this problem. So basically when a request comes in, I want to fork a thread (or background process) and start running that immediately (with no delay). However, s I tried using dalayed_jobs but it seemed to want to a queue, and won't just start the command right away. Is there any way to do this in rails?

Update

#user_controller.rb
def show
  @user = User.find(params[:id])
  @user.update_user  #process to be forked
  render json:@user
end

#user.rb

def update_user
  # code to update user
end
handle_asynchronously :update_user

Thanks,
DO

4

2 に答える 2

1

Delayed Job runs the process immediately after it is triggered (according to your code) since you did not specify when to run it. To get it to work, you can run rake jobs:work but you probably want the process to be run in the background so start the delayed_job daemon in the terminal.

script/delayed_job start
于 2013-03-25T14:18:16.697 に答える
0

From Ruby 1.9 you should be able to do that by calling Process.spawn "your command", example:

pid = Process.spawn("./some_shell_script.sh")
puts "A shell script has just been launched with a Process ID of #{pid}"

This command should spawn a seperate process and return the process id.

于 2013-03-25T12:33:07.993 に答える