queue_classic 0.1.5 → 0.1.6

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/notifier.rb ADDED
@@ -0,0 +1,5 @@
1
+ class Notifier
2
+ def self.deliver(msg)
3
+ `say #{msg}`
4
+ end
5
+ end
@@ -28,5 +28,9 @@ module QC
28
28
  puts "ArgumentError: #{e.inspect}"
29
29
  end
30
30
 
31
+ def logging_enabled?
32
+ true
33
+ end
34
+
31
35
  end
32
36
  end
@@ -34,15 +34,11 @@ module QC
34
34
  @db_string = args[:database]
35
35
  @connection = connection
36
36
  execute("SET client_min_messages TO 'warning'")
37
- execute("LISTEN jobs")
37
+ with_log("setup PG LISTEN") { execute("LISTEN jobs") }
38
38
  end
39
39
 
40
40
  def <<(details)
41
- execute(
42
- "INSERT INTO jobs" +
43
- "(details)" +
44
- "VALUES ('#{details.to_json}')"
45
- )
41
+ execute("INSERT INTO jobs (details) VALUES ('#{details.to_json}')")
46
42
  execute("NOTIFY jobs, 'new-job'")
47
43
  end
48
44
 
@@ -51,7 +47,7 @@ module QC
51
47
  end
52
48
 
53
49
  def delete(job)
54
- execute("DELETE FROM jobs WHERE id = #{job.id}")
50
+ with_log("deleting job #{job.id}") { execute("DELETE FROM jobs WHERE id = #{job.id}") }
55
51
  job
56
52
  end
57
53
 
@@ -66,10 +62,14 @@ module QC
66
62
 
67
63
  def lock_head
68
64
  job = nil
69
- @connection.transaction do
70
- job = find_one {"SELECT * FROM jobs WHERE locked_at IS NULL ORDER BY id ASC LIMIT 1 FOR UPDATE"}
71
- return nil unless job
72
- locked = execute("UPDATE jobs SET locked_at = (CURRENT_TIMESTAMP) WHERE id = #{job.id} AND locked_at IS NULL")
65
+ with_log("start lock transaction") do
66
+ @connection.transaction do
67
+ if job = find_one {"SELECT * FROM jobs WHERE locked_at IS NULL ORDER BY id ASC LIMIT 1 FOR UPDATE"}
68
+ with_log("lock acquired for #{job.inspect}") do
69
+ execute("UPDATE jobs SET locked_at = (CURRENT_TIMESTAMP) WHERE id = #{job.id} AND locked_at IS NULL")
70
+ end
71
+ end
72
+ end
73
73
  end
74
74
  job
75
75
  end
@@ -95,7 +95,7 @@ module QC
95
95
 
96
96
  def find_one
97
97
  res = execute(yield)
98
- if res.cmd_tuples > 0
98
+ if res.count > 0
99
99
  res.map do |r|
100
100
  Job.new(
101
101
  "id" => r["id"],
@@ -120,5 +120,19 @@ module QC
120
120
  end
121
121
  end
122
122
 
123
+ def with_log(msg)
124
+ res = yield
125
+ if QC.logging_enabled?
126
+ log(msg)
127
+ log(res.cmd_status) if res.respond_to?(:cmd_status)
128
+ log(res.result_error_message) if res.respond_to?(:result_error_message)
129
+ end
130
+ res
131
+ end
132
+
133
+ def log(msg)
134
+ puts "| \t" + msg
135
+ end
136
+
123
137
  end
124
138
  end
data/lib/queue_classic.rb CHANGED
@@ -8,8 +8,8 @@ require 'queue_classic/worker'
8
8
  require 'queue_classic/queue'
9
9
  require 'queue_classic/api'
10
10
 
11
- QC::Queue.setup :data_store => QC::DurableArray.new(:database => ENV["DATABASE_URL"])
12
-
13
11
  module QC
14
12
  extend Api
15
13
  end
14
+
15
+ QC::Queue.setup :data_store => QC::DurableArray.new(:database => ENV["DATABASE_URL"])
data/readme.markdown CHANGED
@@ -1,7 +1,7 @@
1
1
  # Queue Classic
2
- __Alpha 0.1.5__
2
+ __Alpha 0.1.6__
3
3
 
4
- _Queue Classic 0.1.5 is not ready for production. However, it is under active development and I expect a beta release within the following months._
4
+ _Queue Classic 0.1.6 is not ready for production. However, it is under active development and I expect a beta release within the following months._
5
5
 
6
6
  Queue Classic is an alternative queueing library for Ruby apps (Rails, Sinatra, Etc...) Queue Classic features __asynchronous__ job polling, database maintained locks and
7
7
  no ridiculous dependencies. As a matter of fact, Queue Classic only requires the __pg__ and __json__.
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 5
9
- version: 0.1.5
8
+ - 6
9
+ version: 0.1.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ryan Smith
@@ -27,7 +27,9 @@ dependencies:
27
27
  - !ruby/object:Gem::Version
28
28
  segments:
29
29
  - 0
30
- version: "0"
30
+ - 10
31
+ - 1
32
+ version: 0.10.1
31
33
  type: :runtime
32
34
  version_requirements: *id001
33
35
  - !ruby/object:Gem::Dependency
@@ -53,6 +55,7 @@ extra_rdoc_files: []
53
55
 
54
56
  files:
55
57
  - readme.markdown
58
+ - lib/notifier.rb
56
59
  - lib/queue_classic/api.rb
57
60
  - lib/queue_classic/durable_array.rb
58
61
  - lib/queue_classic/queue.rb