Any way to destroy or shut down specific supporters?

Is it possible to snipe or cancel certain Sidekiq work orders / work orders - effectively throw an exception or something in the workflow to complete it.

I have some pretty simple background rubies (MRI 1.9.3) in the Sidekiq section (last) that work fine and depend on external systems. External systems may take up different periods of time during which the employee must remain available.

I think I can use the Sidekiq API to access the appropriate employee, but I do not see any "terminate / cancel / all / exit" methods in the documents - is this possible? Is this something else people did?

Ps. I know that I could use an asynchronous loop in a work order to catch the appropriate signals and close ... but this will complicate the situation a bit due to the nature of the external systems.

+4
source share
1 answer

An asynchronous loop is the best way to do this, as sidekiq does not have the ability to shut down.

def perform main_thread = Thread.new do ActiveRecord::Base.connection_pool.with_connection do begin # ... ensure $redis.set some_thread_key, 1 end end end watcher_thread = Thread.new do ActiveRecord::Base.connection_pool.with_connection do until $redis.del(some_thread_key) == 1 do sleep 1 end main_thread.kill until !!main_thread.status == false do sleep 0.1 end end end [main_thread, watcher_thread].each(&:join) end 
0
source

Source: https://habr.com/ru/post/1489493/


All Articles