<commit_before>require "resque/tasks"
require "resque/scheduler/tasks"

task "resque:setup" => :environment<commit_msg>Add Resque tasks to clear old jobs and stale workers<commit_after>require "resque/tasks"
require "resque/scheduler/tasks"

task "resque:setup" => :environment

namespace :resque do
  desc "Clear stuck workers"
  task clear_workers: :environment do
    Resque.workers.each do |w|
      worker_start_time = w.processing.fetch("run_at", Time.current).to_time
      time_running = Time.current - worker_start_time
      max_time_running = 10.minutes

      if time_running > max_time_running
        w.unregister_worker
      end
    end
  end

  desc "Remove old failures"
  task remove_failures: :environment do
    all_failures = Resque::Failure.all(0, Resque::Failure.count)

    all_failures.each_with_object.with_index do |(failure, ids), i|
      if failure["failed_at"].to_time < 2.weeks.ago
        ids << i
      end
    end

    ids.reverse.each { |i| Resque::Failure.remove(i) }
  end
end
{'fraction_non_alphanumeric': 0.09950738916256158, 'fraction_numerical': 0.003940886699507389, 'mean_word_length': 3.6605504587155964, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6235165', 'n_tokens_mistral': 335, 'n_tokens_neox': 325, 'n_words': 79}