queue_classic 0.3.1 → 0.3.2
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/lib/queue_classic/database.rb +17 -13
- data/readme.md +41 -20
- data/test/durable_array_test.rb +0 -8
- data/test/helper.rb +2 -0
- data/test/worker_test.rb +6 -0
- metadata +2 -2
@@ -1,5 +1,6 @@
|
|
1
1
|
module QC
|
2
2
|
class Database
|
3
|
+
@@connection = nil
|
3
4
|
|
4
5
|
MAX_TOP_BOUND = 9
|
5
6
|
DEFAULT_QUEUE_NAME = "queue_classic_jobs"
|
@@ -43,24 +44,25 @@ module QC
|
|
43
44
|
|
44
45
|
def disconnect
|
45
46
|
connection.finish
|
47
|
+
@@connection = nil
|
46
48
|
end
|
47
49
|
|
48
50
|
def connection
|
49
|
-
|
50
|
-
@connection
|
51
|
-
else
|
51
|
+
unless @@connection
|
52
52
|
@name = @db_params.path.gsub("/","")
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
53
|
+
@@connection = PGconn.connect(
|
54
|
+
@db_params.host,
|
55
|
+
@db_params.port || 5432,
|
56
|
+
nil, '',
|
57
|
+
@name,
|
58
|
+
@db_params.user,
|
59
|
+
@db_params.password
|
58
60
|
)
|
59
|
-
|
60
|
-
|
61
|
+
@@connection.exec("LISTEN queue_classic_jobs")
|
62
|
+
@@connection.exec("SET application_name = 'queue_classic'")
|
61
63
|
silence_warnings unless ENV["LOGGING_ENABLED"]
|
62
|
-
@connection
|
63
64
|
end
|
65
|
+
@@connection
|
64
66
|
end
|
65
67
|
|
66
68
|
def drop_table
|
@@ -85,9 +87,12 @@ module QC
|
|
85
87
|
relative_top integer;
|
86
88
|
job_count integer;
|
87
89
|
BEGIN
|
90
|
+
-- The purpose is to release contention for the first spot in the table.
|
91
|
+
-- The select count(*) is going to slow down dequeue performance but allow
|
92
|
+
-- for more workers. Would love to see some optimization here...
|
93
|
+
|
88
94
|
SELECT TRUNC(random() * #{@top_boundry} + 1) INTO relative_top;
|
89
95
|
EXECUTE 'SELECT count(*) FROM' || tname || '' INTO job_count;
|
90
|
-
|
91
96
|
IF job_count < 10 THEN
|
92
97
|
relative_top = 0;
|
93
98
|
END IF;
|
@@ -109,7 +114,6 @@ module QC
|
|
109
114
|
END;
|
110
115
|
END LOOP;
|
111
116
|
|
112
|
-
|
113
117
|
RETURN QUERY EXECUTE 'UPDATE '
|
114
118
|
|| tname::regclass
|
115
119
|
|| ' SET locked_at = (CURRENT_TIMESTAMP)'
|
data/readme.md
CHANGED
@@ -1,33 +1,54 @@
|
|
1
1
|
# Queue Classic
|
2
|
-
|
2
|
+
__0.3.2__ (beta)
|
3
3
|
|
4
|
-
|
4
|
+
Queue Classic is a postgres-backed queueing library that is focused on
|
5
|
+
concurrent job locking, minimizing database load & providing a simple &
|
6
|
+
intuitive user experience.
|
5
7
|
|
6
|
-
|
8
|
+
Queue Classic Features:
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
+
* Support for multiple queues with heterogeneous workers
|
11
|
+
* Utilization of Postgres' PUB/SUB
|
12
|
+
* JSON encoding for jobs
|
13
|
+
* Postgres' rock-solid locking mechanism
|
14
|
+
* Long term support
|
10
15
|
|
11
|
-
|
16
|
+
## Quick Start
|
12
17
|
|
13
|
-
|
18
|
+
See doc/installation.md for Rails instructions
|
14
19
|
|
15
|
-
|
20
|
+
$ gem install queue_classic
|
21
|
+
psql=# CREATE TABLE queue_classic_jobs (id serial, details text, locked_at timestamp);
|
22
|
+
psql=# CREATE INDEX queue_classic_jobs_id_idx ON queue_classic_jobs (id);
|
23
|
+
$ rake qc:load_functions
|
24
|
+
irb: QC.enqueue "Class.method", "arg"
|
25
|
+
$ rake jobs:work
|
16
26
|
|
17
|
-
|
18
|
-
2. psql=# CREATE TABLE queue_classic_jobs (id serial, details text, locked_at timestamp);
|
19
|
-
3. psql=# CREATE INDEX queue_classic_jobs_id_idx ON queue_classic_jobs (id);
|
20
|
-
4. $ rake qc:load_functions
|
21
|
-
5. irb: QC.enqueue "Class.method", "arg"
|
22
|
-
6. $ rake jobs:work
|
27
|
+
## Hacking on Queue Classic
|
23
28
|
|
24
|
-
###
|
29
|
+
### Dependencies
|
25
30
|
|
26
|
-
|
27
|
-
|
31
|
+
* Postgres version 9
|
32
|
+
* Ruby
|
33
|
+
* Gems: pg, json
|
28
34
|
|
29
|
-
###
|
35
|
+
### Running Tests
|
36
|
+
|
37
|
+
* Install dependencies: pg, json (see gemspec)
|
38
|
+
* createdb queue_classic_test
|
39
|
+
* export DATABASE_URL="postgres://username:pass@localhost/queue_classic_test"
|
40
|
+
* rake will run the tests (or turn test/)
|
41
|
+
|
42
|
+
### Building Documentation
|
43
|
+
|
44
|
+
If you are adding new features, please document them in the doc directory. Also,
|
45
|
+
once you have the markdown in place, please run: ruby doc/build.rb to make HTML
|
46
|
+
for the docs.
|
47
|
+
|
48
|
+
## Other Resources
|
49
|
+
|
50
|
+
###[Documentation](https://github.com/ryandotsmith/queue_classic/tree/master/doc)
|
30
51
|
|
31
|
-
|
52
|
+
###[Example Rails App](https://github.com/ryandotsmith/queue_classic_example)
|
32
53
|
|
33
|
-
|
54
|
+
###[Discussion Group](http://groups.google.com/group/queue_classic "discussion group")
|
data/test/durable_array_test.rb
CHANGED
@@ -70,14 +70,6 @@ context "DurableArray" do
|
|
70
70
|
assert_equal([{"job" => "one"},{"job" => "two"}], results)
|
71
71
|
end
|
72
72
|
|
73
|
-
test "connection build db connection from uri" do
|
74
|
-
a = QC::Database.new("postgres://ryandotsmith:@localhost/queue_classic_test")
|
75
|
-
assert_equal "ryandotsmith", a.connection.user
|
76
|
-
assert_equal "localhost", a.connection.host
|
77
|
-
assert_equal "queue_classic_test", a.connection.db
|
78
|
-
a.disconnect
|
79
|
-
end
|
80
|
-
|
81
73
|
test "seach" do
|
82
74
|
@array << {"job" => "A.signature"}
|
83
75
|
jobs = @array.search_details_column("A.signature")
|
data/test/helper.rb
CHANGED
data/test/worker_test.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: queue_classic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.3.
|
5
|
+
version: 0.3.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Ryan Smith
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-08-03 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|