<commit_before>if defined?(ActiveAdmin)
  class Delayed::Job 
    class << self
      def running
        where('failed_at is null and locked_at is not null')
      end

      def failed
        where('failed_at is not null')
      end

      def waiting
        where('failed_at is null and locked_at is null')
      end

    end

    def state
      return 'failed' unless failed_at.blank?
      return 'running' unless locked_at.nil?
      return 'scheduled' if run_at > created_at
      return 'queued'
    end

    def retry!
      j = self
      j.run_at = Time.now
      j.last_error = nil
      j.failed_at = nil
      j.attempts = 0
      j.save
    end
  end

  ActiveAdmin.register Delayed::Job, :as => "Background Job" do
    menu label: "Background Jobs",  title: 'Background Jobs' #:parent => "Dashboard",

    filter :queue

    scope :all
    scope :running
    scope :failed
    scope :waiting

    batch_action 'Retry' do |selection|
      Delayed::Job.find(selection).each do |job|
        job.retry!
      end
      redirect_to admin_background_jobs_path, :notice => "Retrying jobs"
    end


    index do     
      selectable_column                        
      column :id 
      column :queue
      column :priority
      
      column :status do |job|
        case job.state
        when 'failed'
          status_tag "Failed:", :error 
          span "#{job.last_error[0..100]}" 
        when 'running'
          status_tag "Running", :warning
          span "for #{time_ago_in_words(job.locked_at)} @ #{job.locked_by}"   
        when 'scheduled'
          status_tag "Scheduled", :ok
          span "for #{time_ago_in_words(job.run_at)} from now" 
        else
          status_tag "Queued" 
          span "for #{time_ago_in_words(job.created_at)}" 
        end
        
      end

      #column :run_at

      column :attempts

      #column :locked_at
      #column :locked_by
      #column :failed_at
      #column :last_error
      #column :created_at

      default_actions                   
    end 

  end
end<commit_msg>Update to 0.1.0 implement the engine isolation mentioned here: https://github.com/gregbell/active_admin/wiki/Define-a-resource-inside-an-engine to improve loading behavior<commit_after>if defined?(ActiveAdmin)
  class Delayed::Job 
    class << self
      def running
        where('failed_at is null and locked_at is not null')
      end

      def failed
        where('failed_at is not null')
      end

      def waiting
        where('failed_at is null and locked_at is null')
      end

    end

    def state
      return 'failed' unless failed_at.blank?
      return 'running' unless locked_at.nil?
      return 'scheduled' if run_at > created_at
      return 'queued'
    end

    def retry!
      j = self
      j.run_at = Time.now
      j.last_error = nil
      j.failed_at = nil
      j.attempts = 0
      j.save
    end
  end

  ActiveAdmin.register Delayed::Job, :as => "Background Job" do
    menu label: "Background Jobs",  title: 'Background Jobs', parent: "Dashboard"

    actions :index, :show, :update, :edit, :destroy

    filter :queue

    scope :all
    scope :running
    scope :failed
    scope :waiting

    batch_action 'Retry' do |selection|
      Delayed::Job.find(selection).each do |job|
        job.retry!
      end
      redirect_to admin_background_jobs_path, :notice => "Retrying jobs"
    end


    index do     
      selectable_column                        
      column :id 
      column :queue
      column :priority
      
      column :status do |job|
        case job.state
        when 'failed'
          status_tag "Failed:", :error 
          span "#{job.last_error[0..100]}" 
        when 'running'
          status_tag "Running", :warning
          span "for #{time_ago_in_words(job.locked_at)} @ #{job.locked_by}"   
        when 'scheduled'
          status_tag "Scheduled", :ok
          span "for #{time_ago_in_words(job.run_at)} from now" 
        else
          status_tag "Queued" 
          span "for #{time_ago_in_words(job.created_at)}" 
        end
        
      end

      #column :run_at

      column :attempts

      #column :locked_at
      #column :locked_by
      #column :failed_at
      #column :last_error
      #column :created_at

      default_actions                   
    end 

  end
end
{'fraction_non_alphanumeric': 0.08605135322692574, 'fraction_numerical': 0.003007170946102244, 'mean_word_length': 1.8981233243967828, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 10, 'https://': 1, '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': '3012328', 'n_tokens_mistral': 1353, 'n_tokens_neox': 1284, 'n_words': 368}