skip to Main Content

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?

2

Answers


  1. Chosen as BEST ANSWER

    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
    

  2. Dokku’s zero-downtime deploy mechanism will wait a configurable amount of time before running docker container stop. This will send a SIGTERM to your application, and then a SIGKILL after a grace period.

    Your application code should handle SIGTERM and gracefully stop accepting new work, finish old work, and then terminate. This is generally what background processing frameworks do by default, but you may need to configure this in yours or add the functionality if it is a custom framework you wrote.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search