14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/hardcode/worker.rb', line 14
def work(msg)
begin
job = JSON.parse(msg)
source_file = job['source']
if File.extname(source_file).match("^\.(mp4|mp3)$") != nil
FileUtils.mv(source_file, job['dest_dir'], verbose: true)
else
puts output = %x[stack-encode encode --no-progress -l #{STACK_ENCODE_LOG} '#{source_file}']
if $?.success?
puts filename = output[/.*>\s(.*)$/, 1]
puts "Transcoding successful, deleting source file."
FileUtils.mv(File.join(File.dirname(source_file), filename), job['dest_dir'], verbose: true)
FileUtils.rm(source_file, verbose: true)
else
puts "Error: Transcoding failed."
end
end
rescue => e
worker_trace message = "Error: #{e.backtrace}"
raise message
end
worker_trace "Finished: #{job.to_s}"
ack!
end
|