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

module JamRuby

  # periodically scheduled to find jobs that need retrying
  class ScoreHistorySweeper
    extend Resque::Plugins::JamLonelyJob

    @queue = :score_history_sweeper

    @@log = Logging.logger[ScoreHistorySweeper]

    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
      120
    end

    def self.perform
      ScoreHistory.transaction do
        num_rows, sweeped_until = ScoreHistory.migrate_scores
        @@log.debug("migrated #{num_rows} scores")
      end

    end

  end

end