resque-status 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -82,7 +82,8 @@ module Resque
82
82
  # options.
83
83
  #
84
84
  # You should not override this method, rahter the <tt>perform</tt> instance method.
85
- def self.perform(uuid, options = {})
85
+ def self.perform(uuid=nil, options = {})
86
+ uuid ||= Resque::Status.generate_uuid
86
87
  instance = new(uuid, options)
87
88
  instance.safe_perform!
88
89
  instance
@@ -43,7 +43,7 @@
43
43
  <%= partial :next_more, :start => @start, :size => @size %>
44
44
  <% end %>
45
45
 
46
- <%= poll %>
46
+ <%= status_poll(@start) %>
47
47
 
48
48
  <script type="text/javascript" charset="utf-8">
49
49
  jQuery(function($) {
data/lib/resque/status.rb CHANGED
@@ -7,7 +7,7 @@ module Resque
7
7
  # the common status attributes. It also has a number of class methods for
8
8
  # creating/updating/retrieving status objects from Redis
9
9
  class Status < Hash
10
- VERSION = '0.2.0'
10
+ VERSION = '0.2.1'
11
11
 
12
12
  extend Resque::Helpers
13
13
 
@@ -38,8 +38,10 @@ module Resque
38
38
  val
39
39
  end
40
40
 
41
- def self.clear
42
- status_ids.each do |id|
41
+ # clear statuses from redis passing an optional range. See `statuses` for info
42
+ # about ranges
43
+ def self.clear(range_start = nil, range_end = nil)
44
+ status_ids(range_start, range_end).each do |id|
43
45
  redis.del(status_key(id))
44
46
  redis.zrem(set_key, id)
45
47
  end
@@ -64,14 +66,14 @@ module Resque
64
66
  # @param [Numeric] range_end The optional ending range
65
67
  # @example retuning the last 20 statuses
66
68
  # Resque::Status.statuses(0, 20)
67
- def self.statuses(range_start=nil, range_end=nil)
69
+ def self.statuses(range_start = nil, range_end = nil)
68
70
  status_ids(range_start, range_end).collect do |id|
69
71
  get(id)
70
72
  end.compact
71
73
  end
72
74
 
73
75
  # Return the <tt>num</tt> most recent status/job UUIDs in reverse chronological order.
74
- def self.status_ids(range_start=nil, range_end=nil)
76
+ def self.status_ids(range_start = nil, range_end = nil)
75
77
  unless range_end && range_start
76
78
  # Because we want a reverse chronological order, we need to get a range starting
77
79
  # by the higest negative number.
@@ -85,8 +87,6 @@ module Resque
85
87
  else
86
88
  range_end -= 1
87
89
  end
88
-
89
-
90
90
  (redis.zrevrange(set_key, -(range_end.abs), -(range_start.abs)) || []).reverse
91
91
  end
92
92
  end
@@ -200,7 +200,6 @@ module Resque
200
200
  case status
201
201
  when 'completed' then 100
202
202
  when 'queued' then 0
203
- when 'failed' then 100
204
203
  else
205
204
  t = (total == 0 || total.nil?) ? 1 : total
206
205
  (((num || 0).to_f / t.to_f) * 100).to_i
@@ -40,7 +40,11 @@ module Resque
40
40
  content_type "text/plain"
41
41
  @polling = true
42
42
 
43
- @statuses = Resque::Status.statuses
43
+ @start = params[:start].to_i
44
+ @end = @start + (params[:per_page] || 50)
45
+ @statuses = Resque::Status.statuses(@start, @end)
46
+ @size = @statuses.size
47
+
44
48
  status_view(:statuses, {:layout => false})
45
49
  end
46
50
 
@@ -48,6 +52,15 @@ module Resque
48
52
  def status_view(filename, options = {}, locals = {})
49
53
  erb(File.read(File.join(::Resque::StatusServer::VIEW_PATH, "#{filename}.erb")), options, locals)
50
54
  end
55
+
56
+ def status_poll(start)
57
+ if @polling
58
+ text = "Last Updated: #{Time.now.strftime("%H:%M:%S")}"
59
+ else
60
+ text = "<a href='#{url(request.path_info)}.poll?start=#{start}' rel='poll'>Live Poll</a>"
61
+ end
62
+ "<p class='poll'>#{text}</p>"
63
+ end
51
64
  end
52
65
 
53
66
  app.tabs << "Statuses"
@@ -1,52 +1,50 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{resque-status}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Aaron Quint"]
12
- s.date = %q{2010-10-11}
12
+ s.date = %q{2011-01-14}
13
13
  s.description = %q{resque-status is an extension to the resque queue system that provides simple trackable jobs. It provides a Resque::Status class which can set/get the statuses of jobs and a Resque::JobWithStatus class that when subclassed provides easily trackable/killable jobs.}
14
14
  s.email = %q{aaron@quirkey.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.rdoc"
17
+ "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
- ".gitignore",
22
- "LICENSE",
23
- "README.rdoc",
24
- "Rakefile",
25
- "examples/sleep_job.rb",
26
- "init.rb",
27
- "lib/resque/job_with_status.rb",
28
- "lib/resque/server/views/status.erb",
29
- "lib/resque/server/views/status_styles.erb",
30
- "lib/resque/server/views/statuses.erb",
31
- "lib/resque/status.rb",
32
- "lib/resque/status_server.rb",
33
- "resque-status.gemspec",
34
- "test/redis-test.conf",
35
- "test/test_helper.rb",
36
- "test/test_resque-job_with_status.rb",
37
- "test/test_resque-status.rb"
21
+ "LICENSE",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "examples/sleep_job.rb",
25
+ "init.rb",
26
+ "lib/resque/job_with_status.rb",
27
+ "lib/resque/server/views/status.erb",
28
+ "lib/resque/server/views/status_styles.erb",
29
+ "lib/resque/server/views/statuses.erb",
30
+ "lib/resque/status.rb",
31
+ "lib/resque/status_server.rb",
32
+ "resque-status.gemspec",
33
+ "test/redis-test.conf",
34
+ "test/test_helper.rb",
35
+ "test/test_resque-job_with_status.rb",
36
+ "test/test_resque-status.rb"
38
37
  ]
39
38
  s.homepage = %q{http://github.com/quirkey/resque-status}
40
- s.rdoc_options = ["--charset=UTF-8"]
41
39
  s.require_paths = ["lib"]
42
40
  s.rubyforge_project = %q{quirkey}
43
41
  s.rubygems_version = %q{1.3.7}
44
42
  s.summary = %q{resque-status is an extension to the resque queue system that provides simple trackable jobs.}
45
43
  s.test_files = [
44
+ "examples/sleep_job.rb",
46
45
  "test/test_helper.rb",
47
- "test/test_resque-job_with_status.rb",
48
- "test/test_resque-status.rb",
49
- "examples/sleep_job.rb"
46
+ "test/test_resque-job_with_status.rb",
47
+ "test/test_resque-status.rb"
50
48
  ]
51
49
 
52
50
  if s.respond_to? :specification_version then
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque-status
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 2
9
- - 0
10
- version: 0.2.0
8
+ - 1
9
+ version: 0.2.1
11
10
  platform: ruby
12
11
  authors:
13
12
  - Aaron Quint
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-10-11 00:00:00 -07:00
17
+ date: 2011-01-14 00:00:00 -08:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -26,7 +25,6 @@ dependencies:
26
25
  requirements:
27
26
  - - ">="
28
27
  - !ruby/object:Gem::Version
29
- hash: 11
30
28
  segments:
31
29
  - 2
32
30
  - 0
@@ -42,7 +40,6 @@ dependencies:
42
40
  requirements:
43
41
  - - ">="
44
42
  - !ruby/object:Gem::Version
45
- hash: 25
46
43
  segments:
47
44
  - 1
48
45
  - 3
@@ -58,7 +55,6 @@ dependencies:
58
55
  requirements:
59
56
  - - ">="
60
57
  - !ruby/object:Gem::Version
61
- hash: 21
62
58
  segments:
63
59
  - 0
64
60
  - 2
@@ -74,7 +70,6 @@ dependencies:
74
70
  requirements:
75
71
  - - ">="
76
72
  - !ruby/object:Gem::Version
77
- hash: 35
78
73
  segments:
79
74
  - 2
80
75
  - 10
@@ -90,7 +85,6 @@ dependencies:
90
85
  requirements:
91
86
  - - ">="
92
87
  - !ruby/object:Gem::Version
93
- hash: 43
94
88
  segments:
95
89
  - 0
96
90
  - 9
@@ -109,7 +103,6 @@ extra_rdoc_files:
109
103
  - README.rdoc
110
104
  files:
111
105
  - .document
112
- - .gitignore
113
106
  - LICENSE
114
107
  - README.rdoc
115
108
  - Rakefile
@@ -131,8 +124,8 @@ homepage: http://github.com/quirkey/resque-status
131
124
  licenses: []
132
125
 
133
126
  post_install_message:
134
- rdoc_options:
135
- - --charset=UTF-8
127
+ rdoc_options: []
128
+
136
129
  require_paths:
137
130
  - lib
138
131
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -140,7 +133,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
140
133
  requirements:
141
134
  - - ">="
142
135
  - !ruby/object:Gem::Version
143
- hash: 3
144
136
  segments:
145
137
  - 0
146
138
  version: "0"
@@ -149,7 +141,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
141
  requirements:
150
142
  - - ">="
151
143
  - !ruby/object:Gem::Version
152
- hash: 3
153
144
  segments:
154
145
  - 0
155
146
  version: "0"
@@ -161,7 +152,7 @@ signing_key:
161
152
  specification_version: 3
162
153
  summary: resque-status is an extension to the resque queue system that provides simple trackable jobs.
163
154
  test_files:
155
+ - examples/sleep_job.rb
164
156
  - test/test_helper.rb
165
157
  - test/test_resque-job_with_status.rb
166
158
  - test/test_resque-status.rb
167
- - examples/sleep_job.rb
data/.gitignore DELETED
@@ -1,23 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC
22
- doc
23
- .yardoc