Sha256: 9736d7556152854f97592c753d1c62424325951dccc6f8a818c1280c71d9f906

Contents?: true

Size: 1.13 KB

Versions: 4

Compression:

Stored size: 1.13 KB

Contents

module RestFtpDaemon

  # Worker used to clean up the queue deleting expired jobs
  class ConchitaWorker < Shared::WorkerBase

  protected

    def worker_init
      # Load corker conf
      config_section :conchita

      # Check that everything is OK
      return "invalid timer" unless @config[:timer].to_i > 0
      return false
    end

    def worker_after
      # Sleep for a few seconds
      worker_status WORKER_STATUS_WAITING
      sleep @config[:timer]
    end

    def worker_process
      # Announce we are working
      worker_status WORKER_STATUS_CLEANING

      # Cleanup queues according to configured max-age
      $queue.expire JOB_STATUS_FINISHED,  maxage(JOB_STATUS_FINISHED),  @config[:debug]
      $queue.expire JOB_STATUS_FAILED,    maxage(JOB_STATUS_FAILED),    @config[:debug]
      $queue.expire JOB_STATUS_QUEUED,    maxage(JOB_STATUS_QUEUED),    @config[:debug]

      # Force garbage collector
      GC.start if @config["garbage_collector"]

    rescue StandardError => e
      log_error "EXCEPTION: #{e.inspect}"
      sleep 1
    end

  private

    def maxage status
      @config["clean_#{status}"] || 0
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rest-ftp-daemon-0.302.3 lib/rest-ftp-daemon/workers/conchita.rb
rest-ftp-daemon-0.302.2 lib/rest-ftp-daemon/workers/conchita.rb
rest-ftp-daemon-0.302.1 lib/rest-ftp-daemon/workers/conchita.rb
rest-ftp-daemon-0.302.0 lib/rest-ftp-daemon/workers/conchita.rb