namespace :counts do desc 'Process the persistent Counts export queue (run under a process supervisor)' task export_worker: :environment do stopping = false ['TERM', 'INT'].each { |signal| Signal.trap(signal) { stopping = true } } until stopping worked = Rails.application.executor.wrap { CountsExportJobs.work_one } sleep(1) unless worked end end end