2012-11-26 46 views
0

我在我的模型方法中有我从我的控制器调用以下代码。如何通过jruby代码停止curl命令的执行?

Kernel.system"curl -H "Content-Type:application/json" -d "{\"party\":{\"lock_version\":\"0\",\"party_type\":\"Customer\",\"name\":\"xxxxx\",\"sub_type\":\"\",\"description\":\"\",\"contacts_attributes\":{\"1\":{\"name\":\"Jy\",\"email\":\"[email protected]\",\"is_default\":\"true\",\"_destroy\":\"0\"}}}}" "http://localhost:3000/company/customers?auth_token=BhD7P6sXkHkNwVVXx3TF""

当上述代码执行

,在控制台上我可以看到。

% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 202 0 0 0 202 0 0 --:--:-- 0:04:13 --:--:-- 0

但上述过程是保持on.When关闭我的服务器使用CTRL+c我可以看到我的控制台上以下行去。

Started POST "/company/customers?auth_token=BhD7P6sXkHkNwVVXx3TF" for 127.0.0.1 at Mon Nov 26 05:24:13 +0000 2012 Processing by PartiesController#create as JSON Parameters: {"party"=>{"lock_version"=>"0", "party_type"=>"Customer", "name"=>"xxxxx", "sub_type"=>"", "description"=>"", "contacts_attributes"=>{"1"=>{"name"=>"Jy", "email"=>"[email protected]", "is_default"=>"true", "_destroy"=>"0"}}}, "auth_token"=>"BhD7P6sXkHkNwVVXx3TF", "party_type"=>"Customer"} WARNING: Can't verify CSRF token authenticity

这意味着,我的customer成功使用curl

但为什么我需要关闭我的服务器,然后重新启动inorder看到curl命令的结果?有没有解决这个问题的方法,或者我做错了什么?

请帮我,

谢谢。

回答

0

我已经得到了我的问题的答案。 我只是不得不使用-m命令来限制命令的执行时间。

Kernel.system"curl -m 3 -H "Content-Type:application/json" -d "{\"party\":{\"lock_version\":\"0\",\"party_type\":\"Customer\",\"name\":\"xxxxx\",\"sub_type\":\"\",\"description\":\"\",\"contacts_attributes\":{\"1\":{\"name\":\"Jy\",\"email\":\"[email protected]\",\"is_default\":\"true\",\"_destroy\":\"0\"}}}}" "http://localhost:3000/company/customers?auth_token=BhD7P6sXkHkNwVVXx3TF""

这将在3秒内运行......所以现在我不需要关机我的服务器。:-)