Class: Buildkiq::Job
- Inherits:
-
Object
- Object
- Buildkiq::Job
- Defined in:
- lib/buildkiq/job.rb
Instance Attribute Summary collapse
-
#build ⇒ Object
readonly
Returns the value of attribute build.
-
#environments ⇒ Object
readonly
Returns the value of attribute environments.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#project_name ⇒ Object
readonly
Returns the value of attribute project_name.
Instance Method Summary collapse
- #artifact ⇒ Object
- #artifact_upload_success? ⇒ Boolean
- #build_url ⇒ Object
-
#initialize(project_name:, environments:, logger: Logger.new(STDOUT)) ⇒ Job
constructor
A new instance of Job.
- #project ⇒ Object
- #start(source_version: nil, build_cmd: nil) ⇒ Object
- #status ⇒ Object
- #wait_for_job(timeout_sec: build.timeout_in_minutes * 60, sleep_sec: 5) ⇒ Object
- #watch_log_url ⇒ Object
Constructor Details
#initialize(project_name:, environments:, logger: Logger.new(STDOUT)) ⇒ Job
Returns a new instance of Job.
8 9 10 11 12 13 |
# File 'lib/buildkiq/job.rb', line 8 def initialize(project_name:, environments:, logger: Logger.new(STDOUT)) @client = Aws::CodeBuild::Client.new @project_name = project_name @environments = environments @logger = logger end |
Instance Attribute Details
#build ⇒ Object (readonly)
Returns the value of attribute build.
6 7 8 |
# File 'lib/buildkiq/job.rb', line 6 def build @build end |
#environments ⇒ Object (readonly)
Returns the value of attribute environments.
6 7 8 |
# File 'lib/buildkiq/job.rb', line 6 def environments @environments end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
6 7 8 |
# File 'lib/buildkiq/job.rb', line 6 def logger @logger end |
#project_name ⇒ Object (readonly)
Returns the value of attribute project_name.
6 7 8 |
# File 'lib/buildkiq/job.rb', line 6 def project_name @project_name end |
Instance Method Details
#artifact ⇒ Object
59 60 61 |
# File 'lib/buildkiq/job.rb', line 59 def artifact @artifact ||= Artifact.new(self) end |
#artifact_upload_success? ⇒ Boolean
49 50 51 52 53 |
# File 'lib/buildkiq/job.rb', line 49 def artifact_upload_success? !fetch_build.phases.select { |v| v.phase_type == "UPLOAD_ARTIFACTS" && v.phase_status == "SUCCEEDED" }.empty? end |
#build_url ⇒ Object
41 42 43 |
# File 'lib/buildkiq/job.rb', line 41 def build_url "https://#{@client.config.region}.console.aws.amazon.com/codebuild/home#/builds/#{build[:id]}/view/new" end |
#project ⇒ Object
55 56 57 |
# File 'lib/buildkiq/job.rb', line 55 def project @project ||= @client.batch_get_projects(names: [project_name])[0][0] end |
#start(source_version: nil, build_cmd: nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/buildkiq/job.rb', line 15 def start(source_version: nil, build_cmd: nil) params = {project_name: project_name, environment_variables_override: environments} if source_version && source_type == "S3" raise ArgumentError.new("source_version parameter can not be used, project source type is S3") end params[:source_version] = source_version if source_version params[:buildspec_override] = build_spec(build_cmd) if build_cmd logger.info("build parameter: #{params}") @build = @client.start_build(params).build end |
#status ⇒ Object
37 38 39 |
# File 'lib/buildkiq/job.rb', line 37 def status fetch_build.build_status end |
#wait_for_job(timeout_sec: build.timeout_in_minutes * 60, sleep_sec: 5) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/buildkiq/job.rb', line 29 def wait_for_job(timeout_sec: build.timeout_in_minutes * 60, sleep_sec: 5) Timeout.timeout(timeout_sec) do sleep(sleep_sec) until done? end self end |
#watch_log_url ⇒ Object
45 46 47 |
# File 'lib/buildkiq/job.rb', line 45 def watch_log_url build.logs.deep_link if build end |