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.
@@ -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
- if defined? @connection
50
- @connection
51
- else
51
+ unless @@connection
52
52
  @name = @db_params.path.gsub("/","")
53
- @connection = PGconn.connect(
54
- :dbname => @db_params.path.gsub("/",""),
55
- :user => @db_params.user,
56
- :password => @db_params.password,
57
- :host => @db_params.host
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
- @connection.exec("LISTEN queue_classic_jobs")
60
- @connection.exec("SET application_name = 'queue_classic'")
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
- __Beta 0.3.1__
2
+ __0.3.2__ (beta)
3
3
 
4
- __Queue Classic 0.3.1 is in Beta.__ I have been using this library with 30-150 Heroku workers and have had great results.
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
- I am using this in production applications and plan to maintain and support this library for a long time.
8
+ Queue Classic Features:
7
9
 
8
- Queue Classic is a queueing library for Ruby apps (Rails, Sinatra, Etc...) Queue Classic features a blocking dequeue, database maintained locks and
9
- no ridiculous dependencies. As a matter of fact, Queue Classic only requires the __pg__ and __json__.
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
- [Discussion Group](http://groups.google.com/group/queue_classic)
16
+ ## Quick Start
12
17
 
13
- [Wiki](https://github.com/ryandotsmith/queue_classic/wiki)
18
+ See doc/installation.md for Rails instructions
14
19
 
15
- ## Installation
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
- 1. $ gem install queue_classic
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
- ### Upgrade from < 0.2.3 to 0.3.0
29
+ ### Dependencies
25
30
 
26
- $ psql your_database
27
- your_database=# ALTER TABLE jobs RENAME TO queue_classic_jobs;
31
+ * Postgres version 9
32
+ * Ruby
33
+ * Gems: pg, json
28
34
 
29
- ### Dependencies
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
- Postgres version 9
52
+ ###[Example Rails App](https://github.com/ryandotsmith/queue_classic_example)
32
53
 
33
- Ruby (gems: pg, json)
54
+ ###[Discussion Group](http://groups.google.com/group/queue_classic "discussion group")
@@ -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")
@@ -1,6 +1,8 @@
1
1
  $: << File.expand_path("lib")
2
2
  $: << File.expand_path("test")
3
3
 
4
+ ENV['DATABASE_URL'] ||= 'postgres:///queue_classic_test'
5
+
4
6
  require 'queue_classic'
5
7
  require 'database_helpers'
6
8
 
@@ -42,4 +42,10 @@ context "Worker" do
42
42
  @worker.work
43
43
  assert_equal 1, @worker.failed_count
44
44
  end
45
+
46
+ test "only makes one connection" do
47
+ QC.enqueue "TestNotifier.deliver", {}
48
+ @worker.work
49
+ assert_equal 1, QC.connection_status[:total]
50
+ end
45
51
  end
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.1
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-04-26 00:00:00 -07:00
13
+ date: 2011-08-03 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency