summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatija Čupić <matteeyah@gmail.com>2017-12-16 02:39:55 +0100
committerMatija Čupić <matteeyah@gmail.com>2017-12-16 04:00:35 +0100
commit68b95cd01e674cd2dbce45c49f5be04c223b718d (patch)
tree1ddfc864b13c2b411009fef628af5eb98352fc1e
parent291480f5e17fea424692f979db91d2ec62d24dbd (diff)
downloadgitlab-ce-68b95cd01e674cd2dbce45c49f5be04c223b718d.tar.gz
Add CheckGcpProjectBillingWorker
-rw-r--r--app/workers/check_gcp_project_billing_worker.rb16
-rw-r--r--spec/workers/check_gcp_project_billing_worker_spec.rb23
2 files changed, 39 insertions, 0 deletions
diff --git a/app/workers/check_gcp_project_billing_worker.rb b/app/workers/check_gcp_project_billing_worker.rb
new file mode 100644
index 00000000000..97638f65e8d
--- /dev/null
+++ b/app/workers/check_gcp_project_billing_worker.rb
@@ -0,0 +1,16 @@
+class CheckGcpProjectBillingWorker
+ include ApplicationWorker
+
+ def self.redis_shared_state_key_for(token)
+ "gitlab:gcp:#{token}:billing_enabled"
+ end
+
+ def perform(token)
+ return unless token
+
+ billing_enabled = CheckGcpProjectBillingService.new.execute(token)
+ Gitlab::Redis::SharedState.with do |redis|
+ redis.set(self.class.redis_shared_state_key_for(token), billing_enabled)
+ end
+ end
+end
diff --git a/spec/workers/check_gcp_project_billing_worker_spec.rb b/spec/workers/check_gcp_project_billing_worker_spec.rb
new file mode 100644
index 00000000000..c6e624f65be
--- /dev/null
+++ b/spec/workers/check_gcp_project_billing_worker_spec.rb
@@ -0,0 +1,23 @@
+require 'spec_helper'
+
+describe CheckGcpProjectBillingWorker do
+ describe '.perform' do
+ let(:token) { 'bogustoken' }
+ subject { described_class.new.perform(token) }
+
+ it 'calls the service' do
+ expect(CheckGcpProjectBillingService).to receive_message_chain(:new, :execute)
+
+ subject
+ end
+
+ it 'stores billing status in redis' do
+ expect(CheckGcpProjectBillingService).to receive_message_chain(:new, :execute).and_return(true)
+ subject
+
+ Gitlab::Redis::SharedState.with do |redis|
+ expect(redis.get("gitlab:gcp:#{token}:billing_enabled")).to eq('true')
+ end
+ end
+ end
+end