How can I run a continuous background job with Sidekiq?

前端 未结 1 916
星月不相逢
星月不相逢 2021-02-13 22:36

I have been using Sidekiq successfully to run background jobs that are initiated by user actions in a Rails 3.2 application. My particular application involves sending and recei

1条回答
  •  花落未央
    2021-02-13 23:10

    Ruby multithreading is just for that. Spawn a thread in your initializers folder:

    Thread.new do
    
      loop do
    
        for user in User.active
          data = user.get_data
          next if data.blank?
    
          UserDataWorker.perform_async(user.id)
        end
    
        sleep 1
    
      end
    end
    

    If your checks don't need much resources, should be allright.

    0 讨论(0)
提交回复
热议问题