Skip to content
This repository has been archived by the owner on Jan 29, 2022. It is now read-only.

Commit

Permalink
added timestamp to all jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
mediocretes committed Nov 3, 2010
1 parent a79da22 commit 34e5b22
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 12 deletions.
1 change: 1 addition & 0 deletions lib/resque.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ def enable_delay(queue)
# Pushes a job onto a queue. Queue name should be a string and the
# item should be any JSON-able Ruby object.
def push(queue, item)
item[:resque_enqueue_timestamp] = Time.now
if item[:unique]
mongo[queue].update({'_id' => item[:_id]}, item, { :upsert => true})
else
Expand Down
1 change: 0 additions & 1 deletion lib/resque/failure/mongo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def self.count
end

def self.all(start = 0, count = 1)

all_failures = Resque.mongo_failures.find().skip(start.to_i).limit(count.to_i).to_a
all_failures.size == 1 ? all_failures.first : all_failures
end
Expand Down
4 changes: 4 additions & 0 deletions lib/resque/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ def processes_in(delay_until)
return "Immediately (#{time})" if now > delay_until
return time
end

def enqueued_at(resque_enqueue_timestamp)

end

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)
Expand Down
6 changes: 5 additions & 1 deletion lib/resque/server/views/queues.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,30 @@
<tr>
<th>Class</th>
<th>Args1</th>
<th>Enqueued At</th>
</tr>
<% for job in (jobs = resque.peek(queue.to_sym, start, 20)) %>
<tr>
<td class='class'><%= job['class'] %></td>
<td class='args'><%=h job['args'].inspect %></td>
<td class='enqueuedat><%=h enqueued_at(job['resque_enqueue_timestamp']) %></td>
</tr>
<% end %>
<% else %>
<p class='sub'>Showing <%= start = params[:start].to_i %> to <%= start + 20 %> of <b><%=size = resque.size(queue.to_sym)%></b> jobs</p><table class='delays'>
<tr>
<th>Class</th>
<th>Args</th>
<th>Enqueued At</th>
<th>Processes In</th>
</tr>
<% for job in (jobs = resque.peek(queue.to_sym, start, 20, :all_sorted)) %>
<tr>
<td class='class'><%= job['class'] %></td>
<td class='args'><%=h job['args'].inspect %></td>
<td class='enqueuedat'><%=h enqueued_at(job['resque_enqueue_timestamp']) %></td>
<td class='delay'><%=h processes_in(job['delay_until']) %></td>
</tr>
</tr>
<% end %>
<% end %>
<% if jobs.empty? %>
Expand Down
2 changes: 1 addition & 1 deletion lib/resque/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Resque
Version = VERSION = '1.1.3'
Version = VERSION = '1.1.4'
end
Binary file added resque-igo-1.1.4.gem
Binary file not shown.
14 changes: 7 additions & 7 deletions test/resque_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,27 +141,27 @@ def pop_no_id(queue)


test "can pull items off a queue" do
assert_equal({ 'name' => 'chris' }, pop_no_id(:people))
assert_equal({ 'name' => 'bob' }, pop_no_id(:people))
assert_equal({ 'name' => 'mark' }, pop_no_id(:people))
assert_equal('chris', pop_no_id(:people)['name'])
assert_equal('bob', pop_no_id(:people)['name'])
assert_equal('mark', pop_no_id(:people)['name'])
assert_equal nil, Resque.pop(:people)
end

test "knows how big a queue is" do
assert_equal 3, Resque.size(:people)

assert_equal({ 'name' => 'chris' }, pop_no_id(:people))
assert_equal('chris', pop_no_id(:people)['name'])
assert_equal 2, Resque.size(:people)

assert_equal({ 'name' => 'bob' }, pop_no_id(:people))
assert_equal({ 'name' => 'mark' }, pop_no_id(:people))
assert_equal('bob', pop_no_id(:people)['name'])
assert_equal('mark', pop_no_id(:people)['name'])
assert_equal 0, Resque.size(:people)
end

test "can peek at a queue" do
peek = Resque.peek(:people)
peek.delete "_id"
assert_equal({ 'name' => 'chris' }, peek)
assert_equal('chris', peek['name'])
assert_equal 3, Resque.size(:people)
end

Expand Down
6 changes: 4 additions & 2 deletions test/worker_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
test "failed jobs report exception and message" do
Resque::Job.create(:jobs, BadJobWithSyntaxError)
@worker.work(0)
assert_equal('SyntaxError', Resque::Failure.all.first['exception'])
assert_equal('Extra Bad job!', Resque::Failure.all.first['error'])
failure = Resque::Failure.all.is_a?(Array) ? Resque::Failure.all.first : Resque::Failure.all
assert_equal('SyntaxError', failure['exception'])
assert_equal('Extra Bad job!', failure['error'])
end

test "fails uncompleted jobs on exit" do
Expand Down Expand Up @@ -142,6 +143,7 @@
@worker.work(0) do
task = @worker.job
task['payload'].delete "_id"
task['payload'].delete "resque_enqueue_timestamp"
assert_equal({"args"=>[20, "/tmp"], "class"=>"SomeJob"}, task['payload'])
assert task['run_at']
assert_equal 'jobs', task['queue'].to_s
Expand Down

0 comments on commit 34e5b22

Please sign in to comment.