Class: Resque::Server

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/resque/server.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.tabsObject



250
251
252
# File 'lib/resque/server.rb', line 250

def self.tabs
  @tabs ||= ["Overview", "Working", "Failed", "Queues", "Workers", "Stats"]
end

Instance Method Details

#distance_of_time_in_words(from_time, to_time = 0, include_seconds = true, options = {}) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/resque/server.rb', line 121

def distance_of_time_in_words(from_time, to_time = 0, include_seconds = true, options = {})
  from_time = from_time.to_time if from_time.respond_to?(:to_time)
  to_time = to_time.to_time if to_time.respond_to?(:to_time)
  distance_in_minutes = (((to_time - from_time).abs)/60).round
  distance_in_seconds = ((to_time - from_time).abs).round

  ago = from_time > to_time ? ' ago' : ''
  
  
  case distance_in_minutes
  when 0..1
    return distance_in_minutes == 0 ?
    "less than 1 minute" + ago :
      "#{distance_in_minutes} minutes" + ago unless include_seconds
    
    case distance_in_seconds
    when 0..4   then "less than 5 seconds" + ago
    when 5..9   then "less than 10 seconds" + ago
    when 10..19 then "less than 20 seconds" + ago
    when 20..39 then "half a minute" + ago
    when 40..59 then "less than 1 minute" + ago
    else             "1 minute" + ago
    end
    
  when 2..44           then "#{distance_in_minutes} minutes" + ago
  when 45..89          then "about 1 hour" + ago
  when 90..1439        then "about #{(distance_in_minutes.to_f / 60.0).round} hours" + ago
  when 1440..2529      then "about 1 day" + ago
  when 2530..43199     then "about #{(distance_in_minutes.to_f / 1440.0).round} days" + ago
  when 43200..86399    then "about 1 month" + ago
  when 86400..525599   then "about #{(distance_in_minutes.to_f / 43200.0).round} months" + ago
  else
    distance_in_years           = distance_in_minutes / 525600
    minute_offset_for_leap_year = (distance_in_years / 4) * 1440
    remainder                   = ((distance_in_minutes - minute_offset_for_leap_year) % 525600)
    if remainder < 131400
      "about #{distance_in_years} years" + ago
    elsif remainder < 394200
      "over #{distance_in_years} years" + ago
    else
      "almost #{distance_in_years} years" + ago
    end
  end
end

#enqueued_at(resque_enqueue_timestamp) ⇒ Object



114
115
116
117
118
119
# File 'lib/resque/server.rb', line 114

def enqueued_at(resque_enqueue_timestamp)
  return 'Unknown' if resque_enqueue_timestamp.nil?
  now = Time.now
  time = distance_of_time_in_words(now, resque_enqueue_timestamp)
  return time
end

#processes_in(delay_until) ⇒ Object



106
107
108
109
110
111
112
# File 'lib/resque/server.rb', line 106

def processes_in(delay_until)
  return 'Immediately' if delay_until.nil?
  now = Time.now
  time = distance_of_time_in_words(now, delay_until)
  return "Immediately (#{time})" if now > delay_until
  return time
end

#resqueObject



246
247
248
# File 'lib/resque/server.rb', line 246

def resque
  Resque
end

#show(page, layout = true) ⇒ Object



98
99
100
101
102
103
104
# File 'lib/resque/server.rb', line 98

def show(page, layout = true)
  begin
    erb page.to_sym, {:layout => layout}, :resque => Resque
  rescue Errno::ECONNREFUSED
    erb :error, {:layout => false}, :error => "Can't connect to Redis! (#{Resque.redis_id})"
  end
end