perfectqueue 0.7.22 → 0.7.23

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,4 +1,9 @@
1
1
 
2
+ == 2012-08-03 version 0.7.23
3
+
4
+ * Use free slot ratio instead of free slot amount to decide task priorities
5
+
6
+
2
7
  == 2012-07-19 version 0.7.22
3
8
 
4
9
  * Fixed RDBBackend SQL
@@ -15,7 +15,7 @@ class RDBBackend < Backend
15
15
  # connection test
16
16
  }
17
17
  @sql = <<SQL
18
- SELECT id, timeout, data, created_at, resource, max_running-running AS runnable
18
+ SELECT id, timeout, data, created_at, resource, max_running/running AS weight
19
19
  FROM `#{@table}`
20
20
  LEFT JOIN (
21
21
  SELECT resource AS res, COUNT(1) AS running
@@ -24,7 +24,7 @@ LEFT JOIN (
24
24
  GROUP BY resource
25
25
  ) AS R ON resource = res
26
26
  WHERE timeout <= ? AND (max_running-running IS NULL OR max_running-running > 0)
27
- ORDER BY runnable IS NOT NULL, runnable DESC, timeout ASC
27
+ ORDER BY weight IS NOT NULL, weight DESC, timeout ASC
28
28
  LIMIT #{MAX_SELECT_ROW}
29
29
  SQL
30
30
  # sqlite doesn't support SELECT ... FOR UPDATE but
@@ -0,0 +1,70 @@
1
+ #
2
+ # PerfectQueue
3
+ #
4
+ # Copyright (C) 2012 FURUHASHI Sadayuki
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ module PerfectQueue
20
+ module Backend
21
+ class RDBCompatBackend
22
+
23
+ # This module is mostly copied from rdb_backend.rb
24
+ # and should be maintained with it.
25
+
26
+ module ActiveRecordMixin
27
+ def self.included(mod)
28
+ mod.extend(ClassMethods)
29
+ end
30
+
31
+ class ClassMethods
32
+ def submit!(key, type, data, options)
33
+ now = (options[:now] || Time.now).to_i
34
+ run_at = (options[:run_at] || now).to_i
35
+ user = options[:user]
36
+ max_running = options[:max_running]
37
+ data = data ? data.dup : {}
38
+ data['type'] = type
39
+
40
+ create!({
41
+ :id => key,
42
+ :timeout => run_at,
43
+ :data => data.to_json,
44
+ :created_at => now,
45
+ :resource => user,
46
+ :max_running => max_running,
47
+ })
48
+
49
+ rescue ActiveRecord::RecordNotUnique
50
+ raise IdempotentAlreadyExistsError, "task key=#{key} already exists"
51
+ end
52
+
53
+ def cancel_request!(key, options)
54
+ now = (options[:now] || Time.now).to_i
55
+
56
+ o = find_by_id(key)
57
+ if o == nil || o.created_at == nil
58
+ raise AlreadyFinishedError, "task key=#{key} does not exist or already finished."
59
+ end
60
+
61
+ o.created_at = -1
62
+ o.save!
63
+ end
64
+ end
65
+ end
66
+
67
+ end
68
+ end
69
+ end
70
+
@@ -1,5 +1,5 @@
1
1
  module PerfectQueue
2
2
 
3
- VERSION = '0.7.22'
3
+ VERSION = '0.7.23'
4
4
 
5
5
  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.7.22
4
+ version: 0.7.23
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-19 00:00:00.000000000 Z
12
+ date: 2012-08-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sequel
@@ -57,6 +57,7 @@ files:
57
57
  - lib/perfectqueue/backend.rb
58
58
  - lib/perfectqueue/backend/null.rb
59
59
  - lib/perfectqueue/backend/rdb.rb
60
+ - lib/perfectqueue/backend/rdb_compat/active_record_mixin.rb
60
61
  - lib/perfectqueue/backend/simpledb.rb
61
62
  - lib/perfectqueue/command/perfectqueue.rb
62
63
  - lib/perfectqueue/engine.rb