`

spawn plugin 后台运行任务插件

阅读更多
后台 运行 任务
下载spawn
放在vendor/plugins 目录下
在config/environment.rb中配置:

 config.active_record.allow_concurrency=true 


def test
     spawn do
       sleep 11
      12.times {
      
       puts "i"
      }
     

    end
    render :action=>"test"
 end



很开心的是 该程序不会sleep 11 而是执行到这步时候 render :action=>"test" 直接跳转

跳转后你会发现 在console中 过一会才会出现 i 连续 12次

所以run background task就已经完成了!
2
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics