sqew 0.1.1 → 0.2.0
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/README.md +6 -2
- data/lib/sqew.rb +20 -5
- data/lib/sqew/backend/immediate.rb +3 -3
- data/lib/sqew/version.rb +1 -1
- data/spec/sqew_spec.rb +21 -0
- metadata +2 -2
data/README.md
CHANGED
@@ -16,7 +16,7 @@ sqew is a lightweight background processor. You start a single process that will
|
|
16
16
|
* You don't care about the enqueueing or job forking performance.
|
17
17
|
* You don't need multiple queues (this may change soon).
|
18
18
|
|
19
|
-
If these don't fit the bill or you need more power, I recommend you try the
|
19
|
+
If these don't fit the bill or you need more power, I recommend you try the other great gems such as [Resque](https://github.com/defunkt/resque), [Sidekiq](https://github.com/mperham/sidekiq), and [Qu](https://github.com/bkeepers/qu).
|
20
20
|
|
21
21
|
## Rails Installation
|
22
22
|
|
@@ -101,6 +101,10 @@ And the manager will receive the job and start working on it when it can. You ca
|
|
101
101
|
If you're using Rails 4 you can enqueue the job by using the Rails queuing API:
|
102
102
|
|
103
103
|
Rails.queue.push(MyJob, 1, 2)
|
104
|
+
|
105
|
+
## Using Sqew within Tests
|
106
|
+
|
107
|
+
Within your tests, you can set ```Sqew.inline = true``` and jobs will work immediately as they are enqueued and errors will be re-raised.
|
104
108
|
|
105
109
|
## Is it any good?
|
106
110
|
|
@@ -110,7 +114,7 @@ If you're using Rails 4 you can enqueue the job by using the Rails queuing API:
|
|
110
114
|
|
111
115
|
Sqew doesn't use redis or your rails database. It uses [LevelDB](http://code.google.com/p/leveldb/) to manage its persistence. So you don't have to manage/setup anything.
|
112
116
|
|
113
|
-
## Does it work on windows?
|
117
|
+
## Does it work on windows or jruby?
|
114
118
|
|
115
119
|
No. It uses [forking](http://en.wikipedia.org/wiki/Fork_(operating_system\)) heavily.
|
116
120
|
|
data/lib/sqew.rb
CHANGED
@@ -27,16 +27,25 @@ module Sqew
|
|
27
27
|
Qu
|
28
28
|
end
|
29
29
|
|
30
|
-
def server=(raw)
|
31
|
-
URI.parse(raw) # verify it's parsable
|
32
|
-
@server = raw
|
33
|
-
end
|
34
|
-
|
35
30
|
def_delegators :qu, :backend, :backend=, :length, :queues, :reserve, :logger, :logger=, :failure, :failure=
|
36
31
|
end
|
37
32
|
extend ClassMethods
|
38
33
|
|
39
34
|
class << self
|
35
|
+
def server=(raw)
|
36
|
+
URI.parse(raw) # verify it's parsable
|
37
|
+
@server = raw
|
38
|
+
end
|
39
|
+
|
40
|
+
def inline=(inline)
|
41
|
+
self.backend = Sqew::Backend::Immediate.new if inline
|
42
|
+
@inline = inline
|
43
|
+
end
|
44
|
+
|
45
|
+
def inline
|
46
|
+
!! @inline
|
47
|
+
end
|
48
|
+
|
40
49
|
def configure(*args, &block)
|
41
50
|
self.backend = Sqew::Backend::LevelDB.new
|
42
51
|
block.call(self)
|
@@ -50,6 +59,7 @@ module Sqew
|
|
50
59
|
end
|
51
60
|
|
52
61
|
def push(job, *args)
|
62
|
+
return Qu.enqueue(job, *args) if @inline
|
53
63
|
request = Net::HTTP::Post.new("/enqueue")
|
54
64
|
request.body = MultiJson.encode("job" => job.to_s, "args" => args)
|
55
65
|
http.request(request)
|
@@ -57,11 +67,13 @@ module Sqew
|
|
57
67
|
alias_method :enqueue, :push
|
58
68
|
|
59
69
|
def ping
|
70
|
+
return true if @inline
|
60
71
|
request = Net::HTTP::Get.new("/ping")
|
61
72
|
http.request(request)
|
62
73
|
end
|
63
74
|
|
64
75
|
def status
|
76
|
+
raise "Status is not available while Sqew.inline = true" if @inline
|
65
77
|
request = Net::HTTP::Get.new("/status")
|
66
78
|
response = http.request(request)
|
67
79
|
if response.code == "200"
|
@@ -72,6 +84,7 @@ module Sqew
|
|
72
84
|
end
|
73
85
|
|
74
86
|
def set_workers(count)
|
87
|
+
raise "Setting workers is not available while Sqew.inline = true" if @inline
|
75
88
|
request = Net::HTTP::Put.new("/workers")
|
76
89
|
request.body = count.to_s
|
77
90
|
http.request(request)
|
@@ -79,12 +92,14 @@ module Sqew
|
|
79
92
|
alias_method :workers=, :set_workers
|
80
93
|
|
81
94
|
def clear(*queues)
|
95
|
+
raise "Clear is not available while Sqew.inline = true" if @inline
|
82
96
|
request = Net::HTTP::Delete.new("/clear")
|
83
97
|
request.body = queues.join(",")
|
84
98
|
http.request(request)
|
85
99
|
end
|
86
100
|
|
87
101
|
def delete(id)
|
102
|
+
raise "Delete is not available while Sqew.inline = true" if @inline
|
88
103
|
request = Net::HTTP::Delete.new("/#{id}")
|
89
104
|
http.request(request)
|
90
105
|
end
|
data/lib/sqew/version.rb
CHANGED
data/spec/sqew_spec.rb
CHANGED
@@ -38,4 +38,25 @@ describe Sqew do
|
|
38
38
|
thread.terminate
|
39
39
|
end
|
40
40
|
end
|
41
|
+
|
42
|
+
context "inline" do
|
43
|
+
before(:all) do
|
44
|
+
@is_inline = Sqew.inline
|
45
|
+
Sqew.inline = true
|
46
|
+
end
|
47
|
+
|
48
|
+
after(:all) do
|
49
|
+
Sqew.inline = @is_inline
|
50
|
+
end
|
51
|
+
|
52
|
+
it "runs jobs immediately" do
|
53
|
+
TestJob.reset
|
54
|
+
Sqew.push(TestJob, 77)
|
55
|
+
TestJob.testing.should == 77
|
56
|
+
end
|
57
|
+
|
58
|
+
it "raises errors from jobs" do
|
59
|
+
expect {Sqew.push(ErrorJob, -1) }.to raise_error
|
60
|
+
end
|
61
|
+
end
|
41
62
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sqew
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: leveldb-ruby
|