tempestas 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -0
- data/README.md +25 -0
- data/lib/tempest/cluster.rb +66 -0
- data/lib/tempest/node.rb +15 -0
- data/lib/tempest.rb +45 -0
- metadata +62 -0
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Ruby tempest
|
2
|
+
============
|
3
|
+
|
4
|
+
Ruby client for joining a [tempest cluster](https://github.com/athoune/node-tempest).
|
5
|
+
|
6
|
+
Test
|
7
|
+
----
|
8
|
+
|
9
|
+
Launch a redis server:
|
10
|
+
|
11
|
+
redis-server
|
12
|
+
|
13
|
+
Lauch the tests:
|
14
|
+
|
15
|
+
rspec
|
16
|
+
|
17
|
+
Status
|
18
|
+
------
|
19
|
+
|
20
|
+
Early alpha.
|
21
|
+
|
22
|
+
Licence
|
23
|
+
-------
|
24
|
+
|
25
|
+
MIT
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'redis'
|
3
|
+
|
4
|
+
module Tempest
|
5
|
+
|
6
|
+
class Context
|
7
|
+
attr_reader :respond_to, :job_id
|
8
|
+
def initialize cluster, respond_to, job_id
|
9
|
+
@respond_to = respond_to
|
10
|
+
@job_id = job_id
|
11
|
+
@cluster = cluster
|
12
|
+
end
|
13
|
+
|
14
|
+
def stop
|
15
|
+
@cluster.loop = false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class Cluster
|
20
|
+
|
21
|
+
attr_accessor :loop
|
22
|
+
def initialize redis='localhost:6379'
|
23
|
+
@redis = redis
|
24
|
+
@_on = {}
|
25
|
+
@loop = true
|
26
|
+
@id = 0
|
27
|
+
end
|
28
|
+
|
29
|
+
def on action, &block
|
30
|
+
@_on[action] = block
|
31
|
+
end
|
32
|
+
|
33
|
+
def loop
|
34
|
+
@loop = true
|
35
|
+
while @loop
|
36
|
+
task = Tempest.client(@redis).blpop 'working', 0
|
37
|
+
if task
|
38
|
+
cmd, args, answer, job_id = JSON.parse(task[1])
|
39
|
+
@_on[cmd.to_sym].call Context.new(self, answer, job_id), *args
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def answer who, action, job_id, args
|
45
|
+
Tempest.client(who).send action, job_id, args.to_json
|
46
|
+
end
|
47
|
+
|
48
|
+
def work queue, action, args, respond_to
|
49
|
+
#FIXME implement the real id tactic
|
50
|
+
@id += 1
|
51
|
+
Tempest.client(@redis).rpush queue, [action, args, respond_to, @id].to_json
|
52
|
+
@id
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
@clients = {}
|
58
|
+
|
59
|
+
def self.client server
|
60
|
+
unless @clients.key? server
|
61
|
+
hp = server.split(':')
|
62
|
+
@clients[server] = Redis.new host: hp[0], port: hp[1].to_i
|
63
|
+
end
|
64
|
+
@clients[server]
|
65
|
+
end
|
66
|
+
end
|
data/lib/tempest/node.rb
ADDED
data/lib/tempest.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require "tempest/cluster"
|
2
|
+
|
3
|
+
class Tempest_bloc
|
4
|
+
attr_reader :cluster
|
5
|
+
|
6
|
+
def initialize redis, &block
|
7
|
+
@cluster = Tempest::Cluster.new redis
|
8
|
+
instance_eval &block
|
9
|
+
end
|
10
|
+
|
11
|
+
def worker queue, &block
|
12
|
+
Worker.new @cluster, queue, &block
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
def tempest redis='localhost:6379', &block
|
18
|
+
Tempest_bloc.new redis, &block
|
19
|
+
end
|
20
|
+
|
21
|
+
class Worker
|
22
|
+
attr_reader :queue, :cluster
|
23
|
+
def initialize cluster, queue, &block
|
24
|
+
@cluster = cluster
|
25
|
+
@queue = queue
|
26
|
+
instance_eval &block
|
27
|
+
end
|
28
|
+
|
29
|
+
def on action, &block
|
30
|
+
@cluster.on action, &block
|
31
|
+
end
|
32
|
+
|
33
|
+
def work action, respond_to, *args
|
34
|
+
@cluster.work @queue, action, *args, respond_to
|
35
|
+
end
|
36
|
+
|
37
|
+
def start_loop
|
38
|
+
@cluster.loop
|
39
|
+
end
|
40
|
+
|
41
|
+
def stop_loop
|
42
|
+
@cluster.loop = false
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tempestas
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Mathieu Lecarme
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: redis
|
16
|
+
requirement: &2156604640 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - =
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.2.2
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2156604640
|
25
|
+
description: Client for the tempest cluster
|
26
|
+
email: mathieu@garambrogne.net
|
27
|
+
executables: []
|
28
|
+
extensions: []
|
29
|
+
extra_rdoc_files:
|
30
|
+
- README.md
|
31
|
+
files:
|
32
|
+
- README.md
|
33
|
+
- Gemfile
|
34
|
+
- lib/tempest/cluster.rb
|
35
|
+
- lib/tempest/node.rb
|
36
|
+
- lib/tempest.rb
|
37
|
+
homepage: http://github.com/athoune/ruby-tempest
|
38
|
+
licenses: []
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 1.8.10
|
58
|
+
signing_key:
|
59
|
+
specification_version: 3
|
60
|
+
summary: Client for the tempest cluster
|
61
|
+
test_files: []
|
62
|
+
has_rdoc:
|