Search code examples
ruby-on-railsdockerredisworkerdokku

Dokku remove worker without finishing tasks


I have Ruby on Rails app and after I do any deployment with Dokku, I have my old worker running the tasks normally, but when I complete the deploy, after a few seconds this worker is removed and a new one is created without finishing all the tasks that were running. Does anyone know how I get around this? Or that the worker finishes all tasks before removing, or when a worker is created after deploying, the tasks from the old worker go to the new worker? Any indication?


Solution

  • I managed to solve it with a workaround, I created a check_worker.rb file that I call in the predeploy, it silences the workers so as not to take any more tasks, and while there is a worker with tasks being executed, it does not advance with the deploy until it completes all, only after completing all the tasks it completes the deploy

    app.json

    {
      "scripts": {
        "dokku": {
          "predeploy": "ruby check_worker.rb"
        }
      }
    }
    

    check_worker.rb

    #!/usr/bin/env ruby
    require 'sidekiq'
    require 'sidekiq/api'
    ps = Sidekiq::ProcessSet.new
    ps.each(&:quiet!)
    workers = true
    while workers
      works = []
      active_workers = Sidekiq::Workers.new.map do |_process_id, _thread_id, work|
        works = work
      end
      workers = works.length > 0
      if workers
        sleep 2
      end
    end