Class: Pageflow::PollZencoderJob
- Inherits:
-
Object
- Object
- Pageflow::PollZencoderJob
show all
- Extended by:
- StateMachineJob
- Defined in:
- app/jobs/pageflow/poll_zencoder_job.rb
Class Method Summary
collapse
Class Method Details
50
51
52
53
54
55
56
57
58
|
# File 'app/jobs/pageflow/poll_zencoder_job.rb', line 50
def self.fetch_input_details(file, api)
file.meta_data_attributes = api.get_input_details(file.job_id)
rescue ZencoderApi::RecoverableError => e
file.encoding_error_message = e.message
throw(:halt, :pending)
rescue ZencoderApi::Error => e
file.encoding_error_message = e.message
raise
end
|
.fetch_thumbnail(file) ⇒ Object
42
43
44
45
46
47
48
|
# File 'app/jobs/pageflow/poll_zencoder_job.rb', line 42
def self.fetch_thumbnail(file)
return unless file.respond_to?(:thumbnail)
file.thumbnail = URI.parse(file.zencoder_thumbnail.url)
file.poster = URI.parse(file.zencoder_poster.url)
rescue OpenURI::HTTPError
throw(:halt, :pending)
end
|
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'app/jobs/pageflow/poll_zencoder_job.rb', line 7
def self.perform_with_result(file, options, api = ZencoderApi.instance)
options ||= {}
result = catch(:halt) do
poll_zencoder(file, api)
fetch_input_details(file, api)
fetch_thumbnail(file) unless options[:skip_thumbnail]
:ok
end
ensure
file.save!
end
|
.poll_zencoder(file, api) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'app/jobs/pageflow/poll_zencoder_job.rb', line 23
def self.poll_zencoder(file, api)
info = api.get_info(file.job_id)
file.encoding_progress = info[:finished] ? 100 : info[:progress];
file.encoding_error_message = nil
if info[:state] === 'failed'
throw(:halt, :error)
elsif !info[:finished]
throw(:halt, :pending)
end
rescue ZencoderApi::RecoverableError => e
file.encoding_error_message = e.message
throw(:halt, :pending)
rescue ZencoderApi::Error => e
file.encoding_error_message = e.message
raise
end
|