tempestas 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.md +40 -1
  2. data/lib/tempest/cluster.rb +7 -2
  3. metadata +15 -4
data/README.md CHANGED
@@ -3,6 +3,8 @@ Ruby tempest
3
3
 
4
4
  Ruby client for joining a [tempest cluster](https://github.com/athoune/node-tempest).
5
5
 
6
+ With this gem, you can build a worker in plain old sequential ruby with a simple DSL, using your favorite gems.
7
+
6
8
  Test
7
9
  ----
8
10
 
@@ -14,10 +16,47 @@ Lauch the tests:
14
16
 
15
17
  rspec
16
18
 
19
+ Code
20
+ ----
21
+
22
+ The foreman:
23
+
24
+ ```ruby
25
+ require 'tempest'
26
+
27
+ tempest do
28
+ worker :working do #The working queue
29
+ work :foo, nil, 'World' #nil is for 'no response needed'
30
+ end
31
+ end
32
+ ```
33
+
34
+ The worker :
35
+
36
+ ```ruby
37
+ require 'tempest'
38
+
39
+ tempest do
40
+ worker :working do
41
+ on :foo do |context, name|
42
+ p "hello #{name}"
43
+ context.stop # stop the event loop
44
+ end
45
+ end.start_loop #start the event loop
46
+ end
47
+ ```
48
+
49
+ The queue is handled by Redis, you can start many workers, after or before the foreman, it doesn't care.
50
+
17
51
  Status
18
52
  ------
19
53
 
20
- Early alpha.
54
+ Alpha.
55
+
56
+ Tempestas
57
+ ---------
58
+
59
+ The tempest gem already exists, not _tempestas_. Latin ruled the world.
21
60
 
22
61
  Licence
23
62
  -------
@@ -5,7 +5,8 @@ module Tempest
5
5
 
6
6
  class Context
7
7
  attr_reader :respond_to, :job_id
8
- def initialize cluster, respond_to, job_id
8
+ def initialize cluster, action, respond_to, job_id
9
+ @action = action
9
10
  @respond_to = respond_to
10
11
  @job_id = job_id
11
12
  @cluster = cluster
@@ -14,6 +15,10 @@ module Tempest
14
15
  def stop
15
16
  @cluster.loop = false
16
17
  end
18
+
19
+ def answer *args
20
+ Tempest.client(@respond_to).send @action, @job_id, args.to_json
21
+ end
17
22
  end
18
23
 
19
24
  class Cluster
@@ -36,7 +41,7 @@ module Tempest
36
41
  task = Tempest.client(@redis).blpop 'working', 0
37
42
  if task
38
43
  cmd, args, answer, job_id = JSON.parse(task[1])
39
- @_on[cmd.to_sym].call Context.new(self, answer, job_id), *args
44
+ @_on[cmd.to_sym].call Context.new(self, cmd, answer, job_id), *args
40
45
  end
41
46
  end
42
47
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tempestas
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-24 00:00:00.000000000 Z
12
+ date: 2012-01-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redis
16
- requirement: &2156604640 !ruby/object:Gem::Requirement
16
+ requirement: &2153434040 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - =
@@ -21,7 +21,18 @@ dependencies:
21
21
  version: 2.2.2
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2156604640
24
+ version_requirements: *2153434040
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &2153433500 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - =
31
+ - !ruby/object:Gem::Version
32
+ version: '2.7'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *2153433500
25
36
  description: Client for the tempest cluster
26
37
  email: mathieu@garambrogne.net
27
38
  executables: []