Sha256: 3159eeeb13b48a410b918bb6b6434aea27624942c24da65580fe87c8fe4d8497

Contents?: true

Size: 1.22 KB

Versions: 10

Compression:

Stored size: 1.22 KB

Contents

module RocketJob
  # Whether the current process is running inside a Rocket Job server process.
  def self.server?
    @server
  end

  # When running inside a Rocket Job server process, returns
  # true when Rails has been initialized.
  def self.rails?
    @rails
  end

  # When running inside a Rocket Job server process, returns
  # true when running standalone.
  def self.standalone?
    !@rails
  end

  # Returns a human readable duration from the supplied [Float] number of seconds
  def self.seconds_as_duration(seconds)
    return nil unless seconds
    if seconds >= 86400.0 # 1 day
      "#{(seconds / 86400).to_i}d #{Time.at(seconds).strftime('%-Hh %-Mm')}"
    elsif seconds >= 3600.0 # 1 hour
      Time.at(seconds).strftime('%-Hh %-Mm')
    elsif seconds >= 60.0 # 1 minute
      Time.at(seconds).strftime('%-Mm %-Ss')
    elsif seconds >= 1.0 # 1 second
      "#{'%.3f' % seconds}s"
    else
      duration = seconds * 1000
      if defined? JRuby
        "#{duration.to_i}ms"
      else
        duration < 10.0 ? "#{'%.3f' % duration}ms" : "#{'%.1f' % duration}ms"
      end
    end
  end

  # private

  @rails  = false
  @server = false

  def self.server!
    @server = true
  end

  def self.rails!
    @rails = true
  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rocketjob-3.4.3 lib/rocket_job/rocket_job.rb
rocketjob-3.4.2 lib/rocket_job/rocket_job.rb
rocketjob-3.4.1 lib/rocket_job/rocket_job.rb
rocketjob-3.4.0 lib/rocket_job/rocket_job.rb
rocketjob-3.3.4 lib/rocket_job/rocket_job.rb
rocketjob-3.3.3 lib/rocket_job/rocket_job.rb
rocketjob-3.3.2 lib/rocket_job/rocket_job.rb
rocketjob-3.3.1 lib/rocket_job/rocket_job.rb
rocketjob-3.3.0 lib/rocket_job/rocket_job.rb
rocketjob-3.2.1 lib/rocket_job/rocket_job.rb