Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

Commit

Permalink
Set REQUEST_ID env
Browse files Browse the repository at this point in the history
  • Loading branch information
jdlehman committed Feb 1, 2017
1 parent 21cfc90 commit c8834c1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ Alternatively, a block can be passed to the `initialize` method to the same effe
- `repo` String: The git repo identifier
- `git_ref` String: The git branchname or SHA
- `git_sha` String: The git SHA (even if the git ref was a branch name)
- `request_id` String: The unique id of the build request
- `stats` Hash:
- setup `Float`: Amount of time spent in setup
- build `Float`: Total amount of time spent in build (compile/build/slug)
Expand Down
6 changes: 4 additions & 2 deletions lib/slugbuilder/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ def build(clear_cache: false, env: {}, prebuild: nil, postbuild: nil, slug_name:
output: build_output.join('')
}

postbuild.call(repo: @repo, git_ref: @git_ref, git_sha: @git_sha, stats: stats, slug: File.join(@output_dir, @slug_file)) if postbuild
postbuild.call(repo: @repo, git_ref: @git_ref, git_sha: @git_sha, request_id: @request_id, stats: stats, slug: File.join(@output_dir, @slug_file)) if postbuild
if block_given?
yield(repo: @repo, git_ref: @git_ref, git_sha: @git_sha, stats: stats, slug: File.join(@output_dir, @slug_file))
yield(repo: @repo, git_ref: @git_ref, git_sha: @git_sha, request_id: @request_id, stats: stats, slug: File.join(@output_dir, @slug_file))
end
return true
rescue => e
Expand Down Expand Up @@ -94,6 +94,8 @@ def set_environment
load_env_file("#{@cache_dir}/env")
load_env_file("#{@build_dir}/.env")
ENV['STACK'] = 'cedar-14'
@request_id = SecureRandom.urlsafe_base64(32)
ENV['REQUEST_ID'] = @request_id

@env.each do |k, v|
ENV[k.to_s] = v.to_s
Expand Down
4 changes: 2 additions & 2 deletions spec/slugbuilder/builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ def self.call(args)

it 'accepts a postbuild Proc' do
my_proc = ->(args) do
expect(args.keys).to include(:repo, :git_ref, :git_sha, :stats, :slug)
expect(args.keys).to include(:repo, :git_ref, :git_sha, :request_id, :stats, :slug)
end
builder.build(postbuild: my_proc)
end

it 'accepts a postbuild block' do
builder.build do |args|
expect(args.keys).to include(:repo, :git_ref, :git_sha, :stats, :slug)
expect(args.keys).to include(:repo, :git_ref, :git_sha, :request_id, :stats, :slug)
end
end
end
Expand Down

0 comments on commit c8834c1

Please sign in to comment.