Class: FlyAdmin::StopFFmpegJob

Inherits:
ActiveJob::Base
  • Object
show all
Defined in:
app/jobs/fly_admin/stop_f_fmpeg_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(*args) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/jobs/fly_admin/stop_f_fmpeg_job.rb', line 5

def perform(*args)
  video_ids = Video.where(state: Video::FAILURE_STATE).select(:id).map(&:id)
  pid_file = "#{Rails.root}/tmp/pids/ffmpeg_pids.pid"
  if File.exists?(pid_file)

    File.open(pid_file) do |f|
      f.each_line do |line|
        str = /video_(\d+)\ with\ pid:\ (\d+)/.match(line)
        next unless str
        video_id = str[1].to_i
        ffmpeg_pid = str[2].to_i
        if video_ids.include?(video_id)
          system("kill -9 #{ffmpeg_pid}")
        end
      end
    end
    system("rm #{pid_file}")
  end
end