zack 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ = 0.1.2 / 09-11-2010
2
+
3
+ * FIX: Don't read our own messages back (client)
4
+
1
5
  = 0.1.1 / 28-09-2010
2
6
 
3
7
  * Properly deletes jobs.
data/Rakefile CHANGED
@@ -17,7 +17,7 @@ spec = Gem::Specification.new do |s|
17
17
 
18
18
  # Change these as appropriate
19
19
  s.name = "zack"
20
- s.version = "0.1.1"
20
+ s.version = "0.1.2"
21
21
  s.summary = "Ruby RPC calls via beanstalkd"
22
22
  s.authors = ['Kaspar Schiess', 'Patrick Marchi']
23
23
  s.email = ["kaspar.schiess@absurd.li", 'mail@patrickmarchi.ch']
data/lib/zack/client.rb CHANGED
@@ -14,7 +14,9 @@ class Zack::Client
14
14
  # Ain't it beautiful
15
15
  digest = Digest::MD5.new
16
16
  digest << @connection.instance_variable_get('@socket').addr.to_s
17
+
17
18
  @answer_queue_name = "answer_"+digest.hexdigest
19
+ @answer_connection = Beanstalk::Connection.new(server, @answer_queue_name)
18
20
  end
19
21
  end
20
22
 
@@ -31,8 +33,7 @@ class Zack::Client
31
33
  @connection.put message.to_yaml
32
34
 
33
35
  if @with_answer.include? sym
34
- @connection.watch @answer_queue_name
35
- answer = @connection.reserve
36
+ answer = @answer_connection.reserve
36
37
  begin
37
38
  return YAML.load(answer.body)
38
39
  ensure
data/lib/zack/server.rb CHANGED
@@ -27,20 +27,23 @@ class Zack::Server
27
27
  #
28
28
  def handle_request
29
29
  job = @connection.reserve
30
+ sym, args, answer_tube = nil, nil, nil
30
31
  begin
31
32
  sym, args, answer_tube = YAML.load(job.body)
32
-
33
- instance = @factory.produce
34
- retval = instance.send(sym, *args)
35
-
36
- if answer_tube
37
- @connection.use answer_tube
38
- @connection.put retval.to_yaml
39
- @connection.use tube_name
40
- end
41
33
  ensure
34
+ # If yaml decoding crashes, the message is probably invalid. Delete it.
35
+ # If an exception is raised later on, we treat the request as satisfied.
42
36
  job.delete
43
37
  end
38
+
39
+ instance = @factory.produce
40
+ retval = instance.send(sym, *args)
41
+
42
+ if answer_tube
43
+ on_tube(answer_tube) do
44
+ @connection.put retval.to_yaml
45
+ end
46
+ end
44
47
  end
45
48
 
46
49
  # Runs the server and keeps running until the world ends (or the process,
@@ -51,4 +54,15 @@ class Zack::Server
51
54
  handle_request
52
55
  end
53
56
  end
57
+
58
+ private
59
+ def on_tube(temporary_tube_name)
60
+ begin
61
+ @connection.use temporary_tube_name
62
+
63
+ yield
64
+ ensure
65
+ @connection.use @tube_name
66
+ end
67
+ end
54
68
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 1
9
- version: 0.1.1
8
+ - 2
9
+ version: 0.1.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Kaspar Schiess
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-28 00:00:00 +02:00
18
+ date: 2010-11-09 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency