zoukankan      html  css  js  c++  java
  • delayed job

    delayed_job_active_record

    https://github.com/collectiveidea/delayed_job_active_record

    Installation

    (1)Add the gem to your Gemfile:

    gem 'delayed_job_active_record'
    

    Run bundle install.

    (2)If you're using Rails, run the generator to create the migration for the delayed_job table.

    rails g delayed_job:active_record
    bundle exec rake db:migrate
    
    要是觉得不喜欢这个表名,可以在migrate修改表名。
    
    (3)Running Jobs

    script/delayed_job can be used to manage a background process which will start working off jobs.

    To do so, add gem "daemons" to your Gemfile and make sure you've run rails generate delayed_job.

    You can then do the following:

    RAILS_ENV=production script/delayed_job start
    RAILS_ENV=production script/delayed_job stop
    
    # Runs two workers in separate processes.
    RAILS_ENV=production script/delayed_job -n 2 start
    RAILS_ENV=production script/delayed_job stop
    
    # Set the --queue or --queues option to work from a particular queue.
    RAILS_ENV=production script/delayed_job --queue=tracking start
    RAILS_ENV=production script/delayed_job --queues=mailers,tasks start
    
    # Use the --pool option to specify a worker pool. You can use this option multiple times to start different numbers of workers for different queues.
    # The following command will start 1 worker for the tracking queue,
    # 2 workers for the mailers and tasks queues, and 2 workers for any jobs:
    RAILS_ENV=production script/delayed_job --pool=tracking --pool=mailers,tasks:2 --pool=*:2 start
    
    # Runs all available jobs and then exits
    RAILS_ENV=production script/delayed_job start --exit-on-complete
    # or to run in the foreground
    RAILS_ENV=production script/delayed_job run --exit-on-complete
    (4)insert and delete
     def set_push_at
     @video.update_attributes(:will_push_at => params[:cibn_video_broadcast_list][:will_push_at],
     :push_user => current_user_name)
     @video.delay(:run_at => @video.will_push_at).
     send( method_to_perform(@video), {:user_name => current_user_name})
     redirect_to :back, :notice => '操作成功'
     end 
    
     def cancel_push_at
     @video.update_attributes(:will_push_at => nil)
     job = CibnPushDelayedJob.where('handler like ?' ,
     ["", "CibnVideoBroadcastList", "id: #{@video.id}", ""].join('%') ).last
     CibnPushDelayedJob.delete job.try(:id)
     redirect_to :back, :notice => '操作成功'
    
    
  • 相关阅读:
    IP地址和MAC地址,以及arp攻击
    可爱的老婆
    win7 homebasic下,.net2008 连接oracle,提示错误OCIEnvCreate 失败,返回代码为 1,但错误消息文本不可用
    检讨
    数据库索引
    PB调用C#编写的DLL
    用c#开发可供PB调用的COM组件
    关于excel取消科学计数法的问题
    按键码对照
    JSONP学习资料
  • 原文地址:https://www.cnblogs.com/iwangzheng/p/4318013.html
Copyright © 2011-2022 走看看