Module: Sqew
- Extended by:
- SingleForwardable, ClassMethods
- Defined in:
- lib/sqew.rb,
lib/sqew/server.rb,
lib/sqew/worker.rb,
lib/sqew/manager.rb,
lib/sqew/payload.rb,
lib/sqew/railtie.rb,
lib/sqew/version.rb,
lib/sqew/backend/leveldb.rb,
lib/sqew/backend/immediate.rb
Defined Under Namespace
Modules: Backend, ClassMethods
Classes: Manager, Payload, Railtie, Server, Worker
Constant Summary
collapse
- VERSION =
"0.2.0"
Instance Attribute Summary
Attributes included from ClassMethods
#server
Class Method Summary
collapse
qu
Class Method Details
.clear(*queues) ⇒ Object
94
95
96
97
98
99
|
# File 'lib/sqew.rb', line 94
def clear(*queues)
raise "Clear is not available while Sqew.inline = true" if @inline
request = Net::HTTP::Delete.new("/clear")
request.body = queues.join(",")
http.request(request)
end
|
49
50
51
52
53
54
|
# File 'lib/sqew.rb', line 49
def configure(*args, &block)
self.backend = Sqew::Backend::LevelDB.new
block.call(self)
self.server ||= "http://0.0.0.0:9962"
self.db ||= "/tmp/"
end
|
.delete(id) ⇒ Object
101
102
103
104
105
|
# File 'lib/sqew.rb', line 101
def delete(id)
raise "Delete is not available while Sqew.inline = true" if @inline
request = Net::HTTP::Delete.new("/#{id}")
http.request(request)
end
|
.http ⇒ Object
56
57
58
59
|
# File 'lib/sqew.rb', line 56
def http
uri = URI.parse(server)
@http ||= Net::HTTP.new(uri.host, uri.port)
end
|
.inline ⇒ Object
45
46
47
|
# File 'lib/sqew.rb', line 45
def inline
!! @inline
end
|
.inline=(inline) ⇒ Object
40
41
42
43
|
# File 'lib/sqew.rb', line 40
def inline=(inline)
self.backend = Sqew::Backend::Immediate.new if inline
@inline = inline
end
|
.ping ⇒ Object
69
70
71
72
73
|
# File 'lib/sqew.rb', line 69
def ping
return true if @inline
request = Net::HTTP::Get.new("/ping")
http.request(request)
end
|
.push(job, *args) ⇒ Object
Also known as:
enqueue
61
62
63
64
65
66
|
# File 'lib/sqew.rb', line 61
def push(job, *args)
return Qu.enqueue(job, *args) if @inline
request = Net::HTTP::Post.new("/enqueue")
request.body = MultiJson.encode("job" => job.to_s, "args" => args)
http.request(request)
end
|
.server=(raw) ⇒ Object
35
36
37
38
|
# File 'lib/sqew.rb', line 35
def server=(raw)
URI.parse(raw) @server = raw
end
|
.set_workers(count) ⇒ Object
Also known as:
workers=
86
87
88
89
90
91
|
# File 'lib/sqew.rb', line 86
def set_workers(count)
raise "Setting workers is not available while Sqew.inline = true" if @inline
request = Net::HTTP::Put.new("/workers")
request.body = count.to_s
http.request(request)
end
|
.status ⇒ Object
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/sqew.rb', line 75
def status
raise "Status is not available while Sqew.inline = true" if @inline
request = Net::HTTP::Get.new("/status")
response = http.request(request)
if response.code == "200"
MultiJson.decode(http.request(request).body)
else
raise "Error connecting to server #{response.code}:#{response.body}"
end
end
|