Class: KnapsackPro::Client::API::V2::Queues

Inherits:
KnapsackPro::Client::API::V1::Base show all
Defined in:
lib/knapsack_pro/client/api/v2/queues.rb

Constant Summary collapse

CODE_ATTEMPT_CONNECT_TO_QUEUE_FAILED =
'ATTEMPT_CONNECT_TO_QUEUE_FAILED'

Class Method Summary collapse

Methods inherited from KnapsackPro::Client::API::V1::Base

action_class

Class Method Details

.connectObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/knapsack_pro/client/api/v2/queues.rb', line 50

def connect
  git_adapter = KnapsackPro::RepositoryAdapters::GitAdapter.new
  repository_adapter = KnapsackPro::RepositoryAdapterInitiator.call

  request_hash = {
    attempt_connect_to_queue: true,
    batch_index: 0,
    branch: KnapsackPro::Crypto::BranchEncryptor.call(repository_adapter.branch),
    build_author: git_adapter.build_author,
    can_initialize_queue: true,
    commit_authors: git_adapter.commit_authors,
    commit_hash: repository_adapter.commit_hash,
    fixed_queue_split: KnapsackPro::Config::Env.fixed_queue_split_?,
    node_index: KnapsackPro::Config::Env.ci_node_index,
    node_total: KnapsackPro::Config::Env.ci_node_total,
    node_uuid: SecureRandom.uuid,
    skip_pull: true,
    test_queue_id: KnapsackPro::Config::Env.test_queue_id,
    user_seat: KnapsackPro::Config::Env.masked_user_seat,
  }

  action_class.new(
    endpoint_path: '/v2/queues/queue',
    http_method: :post,
    request_hash: request_hash
  )
end

.initialize(paths) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/knapsack_pro/client/api/v2/queues.rb', line 78

def initialize(paths)
  git_adapter = KnapsackPro::RepositoryAdapters::GitAdapter.new
  repository_adapter = KnapsackPro::RepositoryAdapterInitiator.call

  request_hash = {
    attempt_connect_to_queue: false,
    batch_index: 0,
    branch: KnapsackPro::Crypto::BranchEncryptor.call(repository_adapter.branch),
    build_author: git_adapter.build_author,
    can_initialize_queue: true,
    commit_authors: git_adapter.commit_authors,
    commit_hash: repository_adapter.commit_hash,
    fixed_queue_split: KnapsackPro::Config::Env.fixed_queue_split_?,
    node_index: KnapsackPro::Config::Env.ci_node_index,
    node_total: KnapsackPro::Config::Env.ci_node_total,
    node_uuid: SecureRandom.uuid,
    skip_pull: true,
    paths: KnapsackPro::Crypto::Encryptor.paths(paths),
    test_queue_id: KnapsackPro::Config::Env.test_queue_id,
    user_seat: KnapsackPro::Config::Env.masked_user_seat,
  }

  action_class.new(
    endpoint_path: '/v2/queues/queue',
    http_method: :post,
    request_hash: request_hash
  )
end

.queue(args) ⇒ Object



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
42
43
44
45
46
47
48
# File 'lib/knapsack_pro/client/api/v2/queues.rb', line 11

def queue(args)
  request_hash = {
    attempt_connect_to_queue: args.fetch(:attempt_connect_to_queue),
    batch_index: args.fetch(:batch_index),
    branch: args.fetch(:branch),
    can_initialize_queue: args.fetch(:can_initialize_queue),
    commit_hash: args.fetch(:commit_hash),
    fixed_queue_split: KnapsackPro::Config::Env.fixed_queue_split_?,
    node_index: args.fetch(:node_index),
    node_total: args.fetch(:node_total),
    node_uuid: KnapsackPro::Config::Env.node_uuid,
    test_queue_id: KnapsackPro::Config::Env.test_queue_id,
    user_seat: KnapsackPro::Config::Env.masked_user_seat
  }

  if request_hash[:can_initialize_queue] && !request_hash[:attempt_connect_to_queue]
    git_adapter = KnapsackPro::RepositoryAdapters::GitAdapter.new

    request_hash.merge!(
      build_author: git_adapter.build_author,
      commit_authors: git_adapter.commit_authors,
      paths: args.fetch(:paths)
    )
  end

  if !request_hash[:can_initialize_queue] && !request_hash[:attempt_connect_to_queue]
    request_hash.merge!(
      failed_paths: args.fetch(:failed_paths),
      batch_id: args.fetch(:batch_id)
    )
  end

  action_class.new(
    endpoint_path: '/v2/queues/queue',
    http_method: :post,
    request_hash: request_hash
  )
end