blob: 8d80f9c9be3853c55fa6af483443b6485d298934 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
class CheckGcpProjectBillingWorker
include ApplicationWorker
LEASE_TIMEOUT = 15.seconds.to_i
def self.redis_shared_state_key_for(token)
"gitlab:gcp:#{token}:billing_enabled"
end
def perform(token)
return unless token
return unless try_obtain_lease_for(token)
billing_enabled_projects = CheckGcpProjectBillingService.new.execute(token)
Gitlab::Redis::SharedState.with do |redis|
redis.set(self.class.redis_shared_state_key_for(token), !billing_enabled_projects.empty?)
end
end
private
def try_obtain_lease_for(token)
Gitlab::ExclusiveLease
.new("check_gcp_project_billing_worker:#{token}", timeout: LEASE_TIMEOUT)
.try_obtain
end
end
|