Class: Perkins::BuildWorker

Inherits:
Object show all
Includes:
Sidekiq::Worker
Defined in:
lib/perkins/build_worker.rb

Instance Method Summary collapse

Instance Method Details

#perform(repo_id, sha, branch) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/perkins/build_worker.rb', line 9

def perform(repo_id, sha, branch)
  repo = Perkins::Repo.find(repo_id)
  #it actually clone repo and instantiates git data
  repo.load_git

  return if repo.runner.blank?

  repo.runner.sha    = sha
  repo.runner.branch = branch

  send_sse({repo: {id: repo.id, name: repo.name , status: "start"} })

  repo.runner.run(sha)

  report = repo.build_reports.find_by(sha: sha)
  report.send_github_status(sha)

  send_sse({repo: {id: repo.id, name: repo.name , status: "stop", report: report } })
end

#send_sse(msg) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/perkins/build_worker.rb', line 29

def send_sse(msg)
  url = "#{Perkins::Application.instance.sse_endpoint}/sse"
  puts "send sse post to #{url} with msg: #{msg.to_json}".pink
  postData = Net::HTTP.post_form(
    URI.parse(url),
    {'msg'=> msg.to_json }
  )
end