Skip to content
This repository
Browse code

use scrolls, the gem, instad of the file

  • Loading branch information...
commit 470777ac95710b857d01bf3dcd32695528787fcb 1 parent 33feac4
Ryan Smith (ace hacker) authored
4 lib/queue_classic.rb
... ... @@ -1,9 +1,9 @@
  1 +require "scrolls"
1 2 require "pg"
2 3 require "uri"
3 4
4 5 $: << File.expand_path(__FILE__, "lib")
5 6
6   -require "queue_classic/scrolls"
7 7 require "queue_classic/okjson"
8 8 require "queue_classic/conn"
9 9 require "queue_classic/queries"
@@ -11,7 +11,7 @@
11 11 require "queue_classic/worker"
12 12
13 13 module QC
14   - # ENV["QC_LOG_LEVEL"] is used in Scrolls
  14 + # ENV["LOG_LEVEL"] is used in Scrolls
15 15 Scrolls::Log.start
16 16
17 17 Root = File.expand_path("..", File.dirname(__FILE__))
127 lib/queue_classic/scrolls.rb
... ... @@ -1,127 +0,0 @@
1   -require "thread"
2   -
3   -module Scrolls
4   - extend self
5   -
6   - def log(data, &blk)
7   - Log.log(data, &blk)
8   - end
9   -
10   - def log_exception(data, e)
11   - Log.log_exception(data, e)
12   - end
13   -
14   - module Log
15   - extend self
16   -
17   - LOG_LEVEL = (ENV["QC_LOG_LEVEL"] || 3).to_i
18   - LOG_LEVEL_MAP = {
19   - "fatal" => 0,
20   - "error" => 1,
21   - "warn" => 2,
22   - "info" => 3,
23   - "debug" => 4
24   - }
25   -
26   - attr_accessor :stream
27   -
28   - def start(out = nil)
29   - # This allows log_exceptions below to pick up the defined output,
30   - # otherwise stream out to STDERR
31   - @defined = out.nil? ? false : true
32   - sync_stream(out)
33   - end
34   -
35   - def sync_stream(out = nil)
36   - out = STDOUT if out.nil?
37   - @stream = out
38   - @stream.sync = true
39   - end
40   -
41   - def mtx
42   - @mtx ||= Mutex.new
43   - end
44   -
45   - def write(data)
46   - if log_level_ok?(data[:level])
47   - msg = unparse(data)
48   - mtx.synchronize do
49   - @stream.puts(msg)
50   - end
51   - end
52   - end
53   -
54   - def unparse(data)
55   - data.map do |(k, v)|
56   - if (v == true)
57   - k.to_s
58   - elsif v.is_a?(Float)
59   - "#{k}=#{format("%.3f", v)}"
60   - elsif v.nil?
61   - nil
62   - else
63   - v_str = v.to_s
64   - if (v_str =~ /^[a-zA-z0-9\-\_\.]+$/)
65   - "#{k}=#{v_str}"
66   - else
67   - "#{k}=\"#{v_str.sub(/".*/, "...")}\""
68   - end
69   - end
70   - end.compact.join(" ")
71   - end
72   -
73   - def log(data, &blk)
74   - unless blk
75   - write(data)
76   - else
77   - start = Time.now
78   - res = nil
79   - log(data.merge(:at => :start))
80   - begin
81   - res = yield
82   - rescue StandardError, Timeout::Error => e
83   - log(data.merge(
84   - :at => :exception,
85   - :reraise => true,
86   - :class => e.class,
87   - :message => e.message,
88   - :exception_id => e.object_id.abs,
89   - :elapsed => Time.now - start
90   - ))
91   - raise(e)
92   - end
93   - log(data.merge(:at => :finish, :elapsed => Time.now - start))
94   - res
95   - end
96   - end
97   -
98   - def log_exception(data, e)
99   - sync_stream(STDERR) unless @defined
100   - log(data.merge(
101   - :exception => true,
102   - :class => e.class,
103   - :message => e.message,
104   - :exception_id => e.object_id.abs
105   - ))
106   - if e.backtrace
107   - bt = e.backtrace.reverse
108   - bt[0, bt.size-6].each do |line|
109   - log(data.merge(
110   - :exception => true,
111   - :exception_id => e.object_id.abs,
112   - :site => line.gsub(/[`'"]/, "")
113   - ))
114   - end
115   - end
116   - end
117   -
118   - def log_level_ok?(level)
119   - if level
120   - LOG_LEVEL_MAP[level.to_s] <= LOG_LEVEL
121   - else
122   - true
123   - end
124   - end
125   -
126   - end
127   -end
3  queue_classic.gemspec
... ... @@ -1,7 +1,7 @@
1 1 Gem::Specification.new do |s|
2 2 s.name = "queue_classic"
3 3 s.email = "ryan@heroku.com"
4   - s.version = "2.0.0rc11"
  4 + s.version = "2.0.0rc12"
5 5 s.date = "2012-02-29"
6 6 s.description = "queue_classic is a queueing library for Ruby apps. (Rails, Sinatra, Etc...) queue_classic features asynchronous job polling, database maintained locks and no ridiculous dependencies. As a matter of fact, queue_classic only requires pg."
7 7 s.summary = "postgres backed queue"
@@ -18,4 +18,5 @@ Gem::Specification.new do |s|
18 18 s.require_paths = %w[lib]
19 19
20 20 s.add_dependency "pg", "~> 0.13.2"
  21 + s.add_dependency "scrolls", "~> 0.0.8"
21 22 end
2  readme.md
Source Rendered
... ... @@ -1,6 +1,6 @@
1 1 # queue_classic
2 2
3   -v2.0.0rc11
  3 +v2.0.0rc12
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 &

0 comments on commit 470777a

Please sign in to comment.
Something went wrong with that request. Please try again.