Sha256: 007ee6a17e447ebbb7cd9965cd93453eb31d9d0838a084b59b92457cbc3742be

Contents?: true

Size: 1.08 KB

Versions: 3

Compression:

Stored size: 1.08 KB

Contents

module RestFtpDaemon

  class Common

  protected

    def initialize
      # Logger
      @logger = ActiveSupport::Logger.new Settings.logs.workers, 'daily' unless Settings.logs.workers.nil?
    end

    def id
    end

    def progname
    end

    def info message, level = 0
      # progname = "Job [#{id}]" unless id.nil?
      # progname = "Worker [#{id}]" unless worker_id.nil?
      @logger.add(Logger::INFO, "#{'  '*(level+1)} #{message}", progname)
    end

    def notify signal, error = 0, status = {}
      # Skip is not callback URL defined
      url = get :notify
      if url.nil?
        info "Skipping notification (no valid url provided) sig[#{signal}] e[#{error}] s#{status.inspect}"
        return
      end

      # Build notification
      n = RestFtpDaemon::Notification.new
      n.job_id = id
      n.url = url
      n.signal = signal
      n.error = error.inspect
      n.status = status

      # Now, send the notification
      info "Queuing notification key[#{n.key}] sig[#{signal}] url[#{url}]"
      Thread.new(n) do |thread|
        n.notify
      end

    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rest-ftp-daemon-0.60 lib/rest-ftp-daemon/common.rb
rest-ftp-daemon-0.6 lib/rest-ftp-daemon/common.rb
rest-ftp-daemon-0.55 lib/rest-ftp-daemon/common.rb