require 'json'
require 'resque'
require 'resque-retry'
require 'net/http'
require 'digest/md5'

module JamRuby

  # periodically scheduled to find recordings to cleanup
  class RecordingsCleaner
    extend Resque::Plugins::JamLonelyJob

    @queue = :recordings_cleaner

    @@log = Logging.logger[RecordingsCleaner]

    def self.lock_timeout
      # this should be enough time to make sure the job has finished, but not so long that the system isn't recovering from a abandoned job
      1200
    end

    def self.perform
      discarded_recordings = Recording.discarded_and_stale

      discarded_recordings.each do |recording|
        @@log.debug("deleting recording #{recording.id}")
        recording.mark_delete
      end
    end
  end

end