Update

For day 002 of #100DaysOfCode I decided to satisfy my curiosity with a little problem around regualar polling for a job status and displaying a smooth progress bar. I started with using ruby 3.2 and Sidekiq 7. It was relatively easy to get a job running and a web view. Things fell appart when I brought in the sidekiq-status gem. It seems that it uses older Redis ruby gem commands which are no longer available in the minimum version of the reuby redis gem that is a pre-requisite for sidekiq 7. I downgraded sidekiq and was in a bit of dependency hell trying to make everything work. Sidekiq 7 brings in rach 3.0.0 which works different to rack 2.2.4 which is used by Sidekiq 6.5.7. At one time I could not even get the web interface show up and started to tear my hair out.

In the end there was a missing bundle exec when creating the jobs, which meant the latest installed version of Sidekiq (7) was being used for creating jobs but I was running bundle exec to run sidekiq and my make sidekiq-web which meant there was probably an incompatibility. I also at one point assumed that my redis db may have been incompatible so attempted to clear that out with:

redis-cli -h localhost --scan "*"

... stuff

redis-cli -h localhost  FLUSHALL
redis-cli -h localhost  FLUSHDB
killall redis-server
redis-server --daemonize yes
redis-cli -h localhost --scan "*"

... at some stage it returned nothing

In the end not sure if that did anything either. I am right now in the middle of trying to make it work with downgraded gems

gem "rack", "~> 2"              # 2.2.4 rather than 3.0.0
gem "sidekiq", "~> 6"           # 6.5.7 rather than 7.0.0

gem "redis", "~> 4"             # 4.8 not sure if I need to change this?

gem "sidekiq-status", "~> 2.1"  # this is the thing I want to make work

gem "webrick", "~> 1.7"         # needed for rack < 3.0.0

The code

https://github.com/saramic/100-days-of-code/tree/main/002_sidekiq_status

Update 002.1

After stuffing around with libraries I finally worked out that the sidekiq-status gem actually “needs” the configuration, and it was not just a “nice to have” as I had initially assumed. Without the configurationthe jobs do not display correctly on the page and they don’t seem to display their statuses and classes. There still seems to be some errors with the progress percentage and the statuses on the /statuses page? Not only does the percentage come back as higher than 100% but the status goes back to queued?

OK I worked ou the bug in my code

1
class LongSteadyJob
  ...
  def perform(duration = 60)
    @start = Time.now
    while (Time.now.to_f - @start.to_i) < duration
      sleep 1
      at ((Time.now.to_f - @start.to_i) / duration) * 100
    end
  end

The at above reports the percentage “at” that the process is up to. Obviously as the process sleeps for 1 second there is an almost guarantee that the process is going to be over 100% when it finishes. It seems that the sidekiq-status gem takes whatever value as the final value and displays it as well as not knowing what to do with the status to display if the finished job is not exactly 100% done, but say 105% done. Easy fix.

class LongSteadyJob
  ...
  def perform(duration = 60)
    @start = Time.now
    while (Time.now.to_f - @start.to_i) < duration
      sleep 1
      percentage = ((Time.now.to_f - @start.to_i) / duration) * 100
      percentage = 100 if percentage > 100.0
      at percentage
    end
  end

Now finally I get the “janky”, reload every 1 second due to polling, progress bar animation.

sidekiq status polling

Next time to see if I can use some JavaScript to interpolate the values and “fake out” a smooth animation.