perfectqueue 0.8.18 → 0.8.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/ChangeLog CHANGED
@@ -1,4 +1,10 @@
1
1
 
2
+ == 2012-09-04 version 0.8.19
3
+
4
+ * rdb_compat backend uses >= 0 condition instead of IS NOT NULL to work with
5
+ RANGE partitioning of MySQL
6
+
7
+
2
8
  == 2012-09-04 version 0.8.18
3
9
 
4
10
  * rdb_compat backend uses table lock to avoid dead locks with InnoDB
@@ -47,7 +47,7 @@ module PerfectQueue
47
47
  @sql = <<SQL
48
48
  SELECT id, timeout, data, created_at, resource
49
49
  FROM `#{@table}`
50
- WHERE timeout <= ? AND timeout <= ? AND created_at IS NOT NULL
50
+ WHERE timeout <= ? AND timeout <= ? AND created_at >= 0
51
51
  ORDER BY timeout ASC
52
52
  LIMIT ?
53
53
  SQL
@@ -58,10 +58,10 @@ FROM `#{@table}`
58
58
  LEFT JOIN (
59
59
  SELECT resource AS res, COUNT(1) AS running
60
60
  FROM `#{@table}` AS T
61
- WHERE timeout > ? AND created_at IS NOT NULL AND resource IS NOT NULL
61
+ WHERE timeout > ? AND created_at >= 0 AND resource IS NOT NULL
62
62
  GROUP BY resource
63
63
  ) AS R ON resource = res
64
- WHERE timeout <= ? AND created_at IS NOT NULL AND (max_running-running IS NULL OR max_running-running > 0)
64
+ WHERE timeout <= ? AND created_at >= 0 AND (max_running-running IS NULL OR max_running-running > 0)
65
65
  ORDER BY weight IS NOT NULL, weight DESC, timeout ASC
66
66
  LIMIT ?
67
67
  SQL
@@ -134,7 +134,7 @@ SQL
134
134
 
135
135
  connect {
136
136
  #@db.fetch("SELECT id, timeout, data, created_at, resource FROM `#{@table}` WHERE !(created_at IS NULL AND timeout <= ?) ORDER BY timeout ASC;", now) {|row|
137
- @db.fetch("SELECT id, timeout, data, created_at, resource, max_running FROM `#{@table}` ORDER BY timeout ASC;", now) {|row|
137
+ @db.fetch("SELECT id, timeout, data, created_at, resource, max_running FROM `#{@table}` ORDER BY timeout ASC", now) {|row|
138
138
  attributes = create_attributes(now, row)
139
139
  task = TaskWithMetadata.new(@client, row[:id], attributes)
140
140
  yield task
@@ -145,6 +145,7 @@ SQL
145
145
  # => Task
146
146
  def submit(key, type, data, options)
147
147
  now = (options[:now] || Time.now).to_i
148
+ now = 0 if now < 0
148
149
  run_at = (options[:run_at] || now).to_i
149
150
  user = options[:user]
150
151
  user = user.to_s if user
@@ -155,7 +156,7 @@ SQL
155
156
  connect {
156
157
  begin
157
158
  n = @db[
158
- "INSERT INTO `#{@table}` (id, timeout, data, created_at, resource, max_running) VALUES (?, ?, ?, ?, ?, ?);",
159
+ "INSERT INTO `#{@table}` (id, timeout, data, created_at, resource, max_running) VALUES (?, ?, ?, ?, ?, ?)",
159
160
  key, run_at, data.to_json, now, user, max_running
160
161
  ].insert
161
162
  return Task.new(@client, key)
@@ -203,7 +204,7 @@ SQL
203
204
  params = [sql, next_timeout]
204
205
  tasks.each {|t| params << t.key }
205
206
  sql << (1..tasks.size).map { '?' }.join(',')
206
- sql << ") AND created_at IS NOT NULL"
207
+ sql << ") AND created_at >= 0"
207
208
 
208
209
  n = @db[*params].update
209
210
  if n != tasks.size
@@ -220,9 +221,9 @@ SQL
220
221
  def cancel_request(key, options)
221
222
  now = (options[:now] || Time.now).to_i
222
223
 
223
- # created_at=-1 means cancel_requested
224
+ # created_at=0 means cancel_requested
224
225
  connect {
225
- n = @db["UPDATE `#{@table}` SET created_at=-1 WHERE id=? AND created_at IS NOT NULL;", key].update
226
+ n = @db["UPDATE `#{@table}` SET created_at=0 WHERE id=? AND created_at >= 0", key].update
226
227
  if n <= 0
227
228
  raise AlreadyFinishedError, "task key=#{key} does not exist or already finished."
228
229
  end
@@ -241,7 +242,7 @@ SQL
241
242
  key = task_token.key
242
243
 
243
244
  connect {
244
- n = @db["UPDATE `#{@table}` SET timeout=?, created_at=NULL, resource=NULL WHERE id=? AND created_at IS NOT NULL;", delete_timeout, key].update
245
+ n = @db["UPDATE `#{@table}` SET timeout=?, created_at=NULL, resource=NULL WHERE id=? AND created_at >= 0", delete_timeout, key].update
245
246
  if n <= 0
246
247
  raise IdempotentAlreadyFinishedError, "task key=#{key} does not exist or already finished."
247
248
  end
@@ -256,12 +257,12 @@ SQL
256
257
  key = task_token.key
257
258
 
258
259
  connect {
259
- n = @db["UPDATE `#{@table}` SET timeout=? WHERE id=? AND created_at IS NOT NULL;", next_timeout, key].update
260
+ n = @db["UPDATE `#{@table}` SET timeout=? WHERE id=? AND created_at >= 0", next_timeout, key].update
260
261
  if n <= 0
261
262
  row = @db.fetch("SELECT id, timeout, created_at FROM `#{@table}` WHERE id=? LIMIT 1", key).first
262
263
  if row == nil
263
264
  raise PreemptedError, "task key=#{key} does not exist or preempted."
264
- elsif row[:created_at] == -1
265
+ elsif row[:created_at] == 0
265
266
  raise CancelRequestedError, "task key=#{key} is cancel requested."
266
267
  elsif row[:timeout] == next_timeout
267
268
  # ok
@@ -309,8 +310,7 @@ SQL
309
310
  if row[:created_at] === nil
310
311
  created_at = nil # unknown creation time
311
312
  status = TaskStatus::FINISHED
312
- elsif row[:created_at] == -1
313
- created_at = 0
313
+ elsif row[:created_at] == 0
314
314
  status = TaskStatus::CANCEL_REQUESTED
315
315
  elsif now && row[:timeout] < now
316
316
  created_at = row[:created_at]
@@ -1,3 +1,3 @@
1
1
  module PerfectQueue
2
- VERSION = "0.8.18"
2
+ VERSION = "0.8.19"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: perfectqueue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.18
4
+ version: 0.8.19
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: