blob: 3890882b3d4334ff8d2c3361b74b075e3b034c42 (
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# frozen_string_literal: true
module Ci
class ListConfigVariablesService < ::BaseService
include ReactiveCaching
self.reactive_cache_key = ->(service) { [service.class.name, service.id] }
self.reactive_cache_work_type = :external_dependency
self.reactive_cache_worker_finder = ->(id, *_args) { from_cache(id) }
def self.from_cache(id)
project_id, user_id = id.split('-')
project = Project.find(project_id)
user = User.find(user_id)
new(project, user)
end
def execute(sha)
with_reactive_cache(sha) { |result| result }
end
def calculate_reactive_cache(sha)
config = ::Gitlab::Ci::ProjectConfig.new(project: project, sha: sha)
return {} unless config.exists?
result = Gitlab::Ci::YamlProcessor.new(config.content, project: project,
user: current_user,
sha: sha).execute
result.valid? ? result.variables_with_data : {}
end
# Required for ReactiveCaching, it is also used in `reactive_cache_worker_finder`
def id
"#{project.id}-#{current_user.id}"
end
end
end
|