Class: Transcoder

Inherits:
Object
  • Object
show all
Defined in:
app/models/transcoder.rb

Class Method Summary collapse

Class Method Details

.delete(url) ⇒ Object


61
62
63
# File 'app/models/transcoder.rb', line 61

def delete(url)
  call_transcoder(:delete, url)
end

.get(url, *attrs) ⇒ Object


57
58
59
# File 'app/models/transcoder.rb', line 57

def get(url, *attrs)
  call_transcoder(:get, url, *attrs)
end

.host_status(host) ⇒ Object


30
31
32
# File 'app/models/transcoder.rb', line 30

def host_status(host)
  get "#{host.url}/jobs"
end

.job_status(job) ⇒ Object


34
35
36
37
38
# File 'app/models/transcoder.rb', line 34

def job_status(job)
  return unless job.host.try(:url)
  return unless job.remote_job_id
  get "#{job.host.url}/jobs/#{job.remote_job_id}"
end

.job_to_json(job) ⇒ Object


15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/models/transcoder.rb', line 15

def job_to_json(job)
  if job.preset.thumbnail_options.present?
    thumb_opts = MultiJson.load(job.preset.thumbnail_options)
  else
    thumb_opts = nil
  end

  {
    'source_file' => job.source_file,
    'destination_file' => job.destination_file,
    'encoder_options' => job.preset.parameters,
    'thumbnail_options' => thumb_opts
  }
end

.post(url, *attrs) ⇒ Object


53
54
55
# File 'app/models/transcoder.rb', line 53

def post(url, *attrs)
  call_transcoder(:post, url, *attrs)
end

.probe(file) ⇒ Object


46
47
48
49
50
51
# File 'app/models/transcoder.rb', line 46

def probe(file)
  host = Host.with_available_slots.first
  call_transcoder(:post, "#{host.url}/probe", { source_file: file })
rescue => e
  e
end

.remove_job(job) ⇒ Object


40
41
42
43
44
# File 'app/models/transcoder.rb', line 40

def remove_job(job)
  return unless job.host.try(:url)
  return unless job.remote_job_id
  delete("#{job.host.url}/jobs/#{job.remote_job_id}")
end

.schedule(opts) ⇒ Object


3
4
5
6
7
8
9
10
11
12
13
# File 'app/models/transcoder.rb', line 3

def schedule(opts)
  job  = opts[:job]
  host = opts[:host]

  attrs = post("#{host.url}/jobs", job_to_json(job))
  if attrs
    attrs.merge('host_id' => host.id)
  else
    false
  end
end