queue_classic 2.0.0rc12 → 2.0.0rc13
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/queue_classic.rb +2 -0
- data/lib/queue_classic/queries.rb +0 -16
- data/lib/queue_classic/setup.rb +40 -0
- data/lib/queue_classic/tasks.rb +9 -21
- data/lib/queue_classic/worker.rb +2 -0
- data/readme.md +19 -42
- data/sql/drop_ddl.sql +1 -0
- data/test/helper.rb +2 -3
- metadata +6 -5
data/lib/queue_classic.rb
CHANGED
@@ -9,6 +9,7 @@ require "queue_classic/conn"
|
|
9
9
|
require "queue_classic/queries"
|
10
10
|
require "queue_classic/queue"
|
11
11
|
require "queue_classic/worker"
|
12
|
+
require "queue_classic/setup"
|
12
13
|
|
13
14
|
module QC
|
14
15
|
# ENV["LOG_LEVEL"] is used in Scrolls
|
@@ -17,6 +18,7 @@ module QC
|
|
17
18
|
Root = File.expand_path("..", File.dirname(__FILE__))
|
18
19
|
SqlFunctions = File.join(QC::Root, "/sql/ddl.sql")
|
19
20
|
DropSqlFunctions = File.join(QC::Root, "/sql/drop_ddl.sql")
|
21
|
+
CreateTable = File.join(QC::Root, "/sql/create_table.sql")
|
20
22
|
|
21
23
|
# You can use the APP_NAME to query for
|
22
24
|
# postgres related process information in the
|
@@ -38,21 +38,5 @@ module QC
|
|
38
38
|
Conn.execute(*[s, q_name].compact)
|
39
39
|
end
|
40
40
|
|
41
|
-
def load_functions
|
42
|
-
file = File.open(SqlFunctions)
|
43
|
-
Conn.transaction do
|
44
|
-
Conn.execute(file.read)
|
45
|
-
end
|
46
|
-
file.close
|
47
|
-
end
|
48
|
-
|
49
|
-
def drop_functions
|
50
|
-
file = File.open(DropSqlFunctions)
|
51
|
-
Conn.transaction do
|
52
|
-
Conn.execute(file.read)
|
53
|
-
end
|
54
|
-
file.close
|
55
|
-
end
|
56
|
-
|
57
41
|
end
|
58
42
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module QC
|
2
|
+
module Setup
|
3
|
+
extend self
|
4
|
+
|
5
|
+
def create
|
6
|
+
create_table
|
7
|
+
create_functions
|
8
|
+
end
|
9
|
+
|
10
|
+
def drop
|
11
|
+
drop_functions
|
12
|
+
drop_table
|
13
|
+
end
|
14
|
+
|
15
|
+
def create_table
|
16
|
+
Conn.transaction do
|
17
|
+
Conn.execute(File.read(CreateTable))
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def drop_table
|
22
|
+
Conn.transaction do
|
23
|
+
Conn.execute("DROP TABLE IF EXISTS queue_classic_jobs")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def create_functions
|
28
|
+
Conn.transaction do
|
29
|
+
Conn.execute(File.read(SqlFunctions))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def drop_functions
|
34
|
+
Conn.transaction do
|
35
|
+
Conn.execute(File.read(DropSqlFunctions))
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
data/lib/queue_classic/tasks.rb
CHANGED
@@ -6,33 +6,21 @@ end
|
|
6
6
|
namespace :qc do
|
7
7
|
desc "Start a new worker for the (default or $QUEUE) queue"
|
8
8
|
task :work => :environment do
|
9
|
-
QC::Worker.new
|
10
|
-
QC::QUEUE,
|
11
|
-
QC::TOP_BOUND,
|
12
|
-
QC::FORK_WORKER,
|
13
|
-
QC::LISTENING_WORKER,
|
14
|
-
QC::MAX_LOCK_ATTEMPTS
|
15
|
-
).start
|
9
|
+
QC::Worker.new.start
|
16
10
|
end
|
17
11
|
|
18
12
|
desc "Returns the number of jobs in the (default or QUEUE) queue"
|
19
|
-
task :
|
20
|
-
|
21
|
-
QC::QUEUE,
|
22
|
-
QC::TOP_BOUND,
|
23
|
-
QC::FORK_WORKER,
|
24
|
-
QC::LISTENING_WORKER,
|
25
|
-
QC::MAX_LOCK_ATTEMPTS
|
26
|
-
).length
|
13
|
+
task :count => :environment do
|
14
|
+
QC::Worker.new.queue.count
|
27
15
|
end
|
28
16
|
|
29
|
-
desc "
|
30
|
-
task :
|
31
|
-
QC::
|
17
|
+
desc "Setup queue_classic tables and funtions in database"
|
18
|
+
task :create => :environment do
|
19
|
+
QC::Setup.create
|
32
20
|
end
|
33
21
|
|
34
|
-
desc "Remove queue_classic functions from database."
|
35
|
-
task :
|
36
|
-
QC::
|
22
|
+
desc "Remove queue_classic tables and functions from database."
|
23
|
+
task :drop => :environment do
|
24
|
+
QC::Setup.drop
|
37
25
|
end
|
38
26
|
end
|
data/lib/queue_classic/worker.rb
CHANGED
data/readme.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# queue_classic
|
2
2
|
|
3
|
-
v2.0.
|
3
|
+
v2.0.0rc13
|
4
4
|
|
5
5
|
queue_classic is a PostgreSQL-backed queueing library that is focused on
|
6
6
|
concurrent job locking, minimizing database load & providing a simple &
|
@@ -10,7 +10,7 @@ queue_classic features:
|
|
10
10
|
|
11
11
|
* Support for multiple queues with heterogeneous workers
|
12
12
|
* Utilization of Postgres' PUB/SUB
|
13
|
-
* JSON encoding
|
13
|
+
* JSON encoding
|
14
14
|
* Forking workers
|
15
15
|
* Postgres' rock-solid locking mechanism
|
16
16
|
* Fuzzy-FIFO support [academic paper](http://www.cs.tau.ac.il/~shanir/nir-pubs-web/Papers/Lock_Free.pdf)
|
@@ -19,7 +19,7 @@ queue_classic features:
|
|
19
19
|
|
20
20
|
## Proven
|
21
21
|
|
22
|
-
|
22
|
+
queue_classic was designed out of necessity. I needed a message queue that was
|
23
23
|
fast, reliable, and low maintenance. It was built upon PostgreSQL out of a motivation
|
24
24
|
of not wanting to add a redis or 0MQ service to my network of services. It boasts
|
25
25
|
a small API and very few features. It was designed to be simple. Thus, if you need
|
@@ -55,13 +55,12 @@ database migration.
|
|
55
55
|
### Quick Start
|
56
56
|
|
57
57
|
```bash
|
58
|
+
$ gem install queue_classic
|
58
59
|
$ createdb queue_classic_test
|
59
|
-
$ psql queue_classic_test -c "CREATE TABLE queue_classic_jobs (id serial, q_name varchar(255), method varchar(255), args text, locked_at timestamp);"
|
60
60
|
$ export QC_DATABASE_URL="postgres://username:password@localhost/queue_classic_test"
|
61
|
-
$
|
62
|
-
$ ruby -r queue_classic -e "QC::Queries.load_functions"
|
61
|
+
$ ruby -r queue_classic -e "QC::Setup.create"
|
63
62
|
$ ruby -r queue_classic -e "QC.enqueue('Kernel.puts', 'hello world')"
|
64
|
-
$ ruby -r queue_classic -e "QC::Worker.new.
|
63
|
+
$ ruby -r queue_classic -e "QC::Worker.new.work"
|
65
64
|
```
|
66
65
|
|
67
66
|
### Ruby on Rails Setup
|
@@ -90,24 +89,16 @@ ENV["DATABASE_URL"] = "postgres://username:password@localhost/database_name"
|
|
90
89
|
**db/migrations/add_queue_classic.rb**
|
91
90
|
|
92
91
|
```ruby
|
93
|
-
|
92
|
+
require 'queue_classic'
|
93
|
+
|
94
|
+
class AddQueueClassic < ActiveRecord::Migration
|
94
95
|
|
95
96
|
def self.up
|
96
|
-
|
97
|
-
t.string :q_name
|
98
|
-
t.string :method
|
99
|
-
t.text :args
|
100
|
-
t.timestamp :locked_at
|
101
|
-
end
|
102
|
-
add_index :queue_classic_jobs, :id
|
103
|
-
require "queue_classic"
|
104
|
-
QC::Queries.load_functions
|
97
|
+
QC::Setup.create
|
105
98
|
end
|
106
99
|
|
107
100
|
def self.down
|
108
|
-
|
109
|
-
require "queue_classic"
|
110
|
-
QC::Queries.drop_functions
|
101
|
+
QC::Setup.drop
|
111
102
|
end
|
112
103
|
|
113
104
|
end
|
@@ -118,23 +109,11 @@ end
|
|
118
109
|
**db/migrations/1_add_queue_classic.rb**
|
119
110
|
|
120
111
|
```ruby
|
121
|
-
|
122
|
-
up do
|
123
|
-
create_table :queue_classic_jobs do
|
124
|
-
primary_key :id
|
125
|
-
String :q_name
|
126
|
-
String :details
|
127
|
-
Time :locked_at
|
128
|
-
end
|
129
|
-
require "queue_classic"
|
130
|
-
QC::Queries.load_functions
|
131
|
-
end
|
112
|
+
require 'queue_classic'
|
132
113
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
QC::Queries.drop_functions
|
137
|
-
end
|
114
|
+
Sequel.migration do
|
115
|
+
up {QC::Setup.create}
|
116
|
+
down {QC::Setup.down}
|
138
117
|
end
|
139
118
|
```
|
140
119
|
|
@@ -178,7 +157,7 @@ QC.enqueue("Kernel.printf", "hello %s", "world")
|
|
178
157
|
# This method has a hash argument.
|
179
158
|
QC.enqueue("Kernel.puts", {"hello" => "world"})
|
180
159
|
|
181
|
-
# This method has
|
160
|
+
# This method has an array argument.
|
182
161
|
QC.enqueue("Kernel.puts", ["hello", "world"])
|
183
162
|
```
|
184
163
|
|
@@ -219,7 +198,7 @@ p_queue.enqueue("Kernel.printf", "hello %s", "world")
|
|
219
198
|
# This method has a hash argument.
|
220
199
|
p_queue.enqueue("Kernel.puts", {"hello" => "world"})
|
221
200
|
|
222
|
-
# This method has
|
201
|
+
# This method has an array argument.
|
223
202
|
p_queue.enqueue("Kernel.puts", ["hello", "world"])
|
224
203
|
```
|
225
204
|
|
@@ -265,8 +244,7 @@ trap('TERM') {exit}
|
|
265
244
|
|
266
245
|
require "your_app"
|
267
246
|
require "queue_classic"
|
268
|
-
|
269
|
-
worker.start
|
247
|
+
QC::Worker.new.start
|
270
248
|
```
|
271
249
|
|
272
250
|
#### Sublcass QC::Worker
|
@@ -312,8 +290,7 @@ require "your_app"
|
|
312
290
|
require "queue_classic"
|
313
291
|
require "my_worker"
|
314
292
|
|
315
|
-
|
316
|
-
worker.start
|
293
|
+
MyWorker.new.start
|
317
294
|
```
|
318
295
|
|
319
296
|
#### QC::Worker Details
|
data/sql/drop_ddl.sql
CHANGED
data/test/helper.rb
CHANGED
@@ -19,9 +19,8 @@ class QCTest < MiniTest::Unit::TestCase
|
|
19
19
|
|
20
20
|
def init_db(table_name="queue_classic_jobs")
|
21
21
|
QC::Conn.execute("SET client_min_messages TO 'warning'")
|
22
|
-
QC::
|
23
|
-
QC::
|
24
|
-
QC::Queries.load_functions
|
22
|
+
QC::Setup.drop
|
23
|
+
QC::Setup.create
|
25
24
|
QC::Conn.disconnect
|
26
25
|
end
|
27
26
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: queue_classic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.0rc13
|
5
5
|
prerelease: 5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-02-29 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: pg
|
16
|
-
requirement: &
|
16
|
+
requirement: &18438700 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.13.2
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *18438700
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: scrolls
|
27
|
-
requirement: &
|
27
|
+
requirement: &18438040 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: 0.0.8
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *18438040
|
36
36
|
description: queue_classic is a queueing library for Ruby apps. (Rails, Sinatra, Etc...)
|
37
37
|
queue_classic features asynchronous job polling, database maintained locks and no
|
38
38
|
ridiculous dependencies. As a matter of fact, queue_classic only requires pg.
|
@@ -49,6 +49,7 @@ files:
|
|
49
49
|
- lib/queue_classic/worker.rb
|
50
50
|
- lib/queue_classic/queue.rb
|
51
51
|
- lib/queue_classic/tasks.rb
|
52
|
+
- lib/queue_classic/setup.rb
|
52
53
|
- lib/queue_classic/queries.rb
|
53
54
|
- lib/queue_classic.rb
|
54
55
|
- test/worker_test.rb
|