Class: PlatformSdk::Sidekiq::EcsTaskProtectionMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/platform_sdk/sidekiq/ecs_task_protection_middleware.rb

Constant Summary collapse

ECS_AGENT_URI =
ENV['ECS_AGENT_URI']
STATE_ENDPOINT =
"#{ECS_AGENT_URI}/task-protection/v1/state"
@@mutex =
Mutex.new
@@active_jobs =
0

Instance Method Summary collapse

Instance Method Details

#call(_, _, _) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/platform_sdk/sidekiq/ecs_task_protection_middleware.rb', line 12

def call(_, _, _)
  @@mutex.synchronize do
    @@active_jobs += 1
    set_task_protection(true) if @@active_jobs == 1
  end

  begin
    yield
  ensure
    @@mutex.synchronize do
      @@active_jobs -= 1
      set_task_protection(false) if @@active_jobs == 0
    end
  end
end