untied 0.0.1 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +34 -4
- data/examples/consumer-daemon/.rvmrc +48 -0
- data/examples/consumer-daemon/Gemfile +6 -0
- data/examples/consumer-daemon/README.mkd +31 -0
- data/examples/consumer-daemon/consumerd.rb +20 -0
- data/examples/consumer-daemon/observer.rb +16 -0
- data/lib/untied/version.rb +1 -1
- data/lib/untied.rb +0 -15
- data/untied.gemspec +2 -3
- metadata +20 -25
data/README.md
CHANGED
@@ -58,7 +58,35 @@ class MyDoorkeeper
|
|
58
58
|
end
|
59
59
|
```
|
60
60
|
|
61
|
-
The watcher defined above will propagate Users instances when they are created or updated.
|
61
|
+
The watcher defined above will propagate Users instances when they are created or updated. The ``to_json`` will be called whenever the model is propagated.
|
62
|
+
|
63
|
+
#### Models representers
|
64
|
+
|
65
|
+
You can use gems such as [ROAR](https://github.com/apotonick/roar) or [representable](https://github.com/apotonick/representable) to define how your models will be mapped into JSONs:
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
require 'roar/representer/json'
|
69
|
+
|
70
|
+
module UserRepresenter
|
71
|
+
include Roar::Representer::JSON
|
72
|
+
|
73
|
+
property :complete_name
|
74
|
+
|
75
|
+
def complete_name
|
76
|
+
"#{self.frist_name} #{self.last_name}"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
class DoorkeeperWithRepresenter
|
81
|
+
include Untied::Doorkeeper
|
82
|
+
|
83
|
+
def initialize
|
84
|
+
watch User, :after_create, :represent_with => UserRepresenter
|
85
|
+
end
|
86
|
+
end
|
87
|
+
```
|
88
|
+
|
89
|
+
Untied will extend the user instance with ``UserRepresenter`` just before sending it into the wire.
|
62
90
|
|
63
91
|
### Consumer
|
64
92
|
|
@@ -85,9 +113,14 @@ Activating observers:
|
|
85
113
|
```ruby
|
86
114
|
Untied::Consumer.configure do |config|
|
87
115
|
config.observers = [UserObserver]
|
116
|
+
config.abort_on_exception = false # default: false
|
88
117
|
end
|
89
118
|
```
|
90
119
|
|
120
|
+
You should start the consumer running the ``untied:consumer:worker`` Raketask.
|
121
|
+
|
122
|
+
The ``abort_on_exception`` configuration tells if the worker should ignore Exception thrown. If set to true the exception and the stacktrace will be logged but the worker will not stop. This is recomended for production environments.
|
123
|
+
|
91
124
|
## Internals
|
92
125
|
|
93
126
|
TODO
|
@@ -95,10 +128,7 @@ TODO
|
|
95
128
|
## What need to be done?
|
96
129
|
|
97
130
|
- Make it ActiveRecord independent.
|
98
|
-
- Add instructions about how to initialize the worker.
|
99
131
|
- Failsafeness
|
100
|
-
- Do not rely on Pub class name
|
101
|
-
|
102
132
|
|
103
133
|
## Contributing
|
104
134
|
|
@@ -0,0 +1,48 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
5
|
+
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
|
7
|
+
# Only full ruby name is supported here, for short names use:
|
8
|
+
# echo "rvm use 1.9.3" > .rvmrc
|
9
|
+
environment_id="ruby-1.9.3-p194"
|
10
|
+
|
11
|
+
# Uncomment the following lines if you want to verify rvm version per project
|
12
|
+
# rvmrc_rvm_version="1.14.5 (master)" # 1.10.1 seams as a safe start
|
13
|
+
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
|
14
|
+
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
|
15
|
+
# return 1
|
16
|
+
# }
|
17
|
+
|
18
|
+
# First we attempt to load the desired environment directly from the environment
|
19
|
+
# file. This is very fast and efficient compared to running through the entire
|
20
|
+
# CLI and selector. If you want feedback on which environment was used then
|
21
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
22
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
|
23
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
24
|
+
then
|
25
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
26
|
+
[[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
|
27
|
+
\. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
|
28
|
+
else
|
29
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
30
|
+
rvm --create "$environment_id" || {
|
31
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
32
|
+
return 1
|
33
|
+
}
|
34
|
+
fi
|
35
|
+
|
36
|
+
# If you use bundler, this might be useful to you:
|
37
|
+
# if [[ -s Gemfile ]] && {
|
38
|
+
# ! builtin command -v bundle >/dev/null ||
|
39
|
+
# builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
|
40
|
+
# }
|
41
|
+
# then
|
42
|
+
# printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
|
43
|
+
# gem install bundler
|
44
|
+
# fi
|
45
|
+
# if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
|
46
|
+
# then
|
47
|
+
# bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
|
48
|
+
# fi
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# Untied consumer as a deamon proccess
|
2
|
+
|
3
|
+
Here is an example of how to run untied consumer in background. This is useful for deployment automation. We also keep the process ID on a file so you can monitor the process using Monit or God.
|
4
|
+
|
5
|
+
## How to
|
6
|
+
|
7
|
+
Add the following line to your Gemfile:
|
8
|
+
|
9
|
+
```
|
10
|
+
gem 'daemons'
|
11
|
+
```
|
12
|
+
|
13
|
+
Or simple install the [daemons](http://daemons.rubyforge.org/) gem using ``gem install daemons``.
|
14
|
+
|
15
|
+
That is it, you should call the method ``daemonize`` from the worker class and provide the log and pid directories absolute paths.
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
worker = Untied::Consumer::Worker.new
|
19
|
+
worker.daemonize(:pids_dir => pids_dir, :log_dir => log_dir)
|
20
|
+
```
|
21
|
+
|
22
|
+
Now you have access to the following commands:
|
23
|
+
|
24
|
+
```sh
|
25
|
+
$ ruby consumerd.rb start
|
26
|
+
$ ruby consumerd.rb status
|
27
|
+
untiedc: running [pid 52324]
|
28
|
+
$ ruby consumerd.rb stop
|
29
|
+
untiedc: trying to stop process with pid 52324...
|
30
|
+
untiedc: process with pid 52324 successfully stopped.
|
31
|
+
```
|
@@ -0,0 +1,20 @@
|
|
1
|
+
$:.unshift File.expand_path(File.dirname(__FILE__))
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "amqp"
|
5
|
+
require "untied-consumer"
|
6
|
+
require "untied-consumer/worker"
|
7
|
+
require "daemons"
|
8
|
+
|
9
|
+
require "observer"
|
10
|
+
|
11
|
+
# Enabling the observer defined in observer.rb
|
12
|
+
Untied::Consumer.configure do |c|
|
13
|
+
c.observers = [Observer]
|
14
|
+
end
|
15
|
+
|
16
|
+
log_dir = File.expand_path File.join(File.dirname(__FILE__), 'log')
|
17
|
+
pids_dir = File.expand_path File.join(File.dirname(__FILE__), 'tmp', 'pids')
|
18
|
+
|
19
|
+
worker = Untied::Consumer::Worker.new
|
20
|
+
worker.daemonize(:pids_dir => pids_dir, :log_dir => log_dir)
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
# Here you should define the method which are going to be called when the
|
3
|
+
# publisher sends some event.
|
4
|
+
class Observer < Untied::Consumer::Observer
|
5
|
+
observe :user, :from => :core
|
6
|
+
|
7
|
+
def after_create(model)
|
8
|
+
puts "An user was created on Goliath server, yay!"
|
9
|
+
puts model.inspect
|
10
|
+
end
|
11
|
+
|
12
|
+
def after_update(model)
|
13
|
+
puts "An user was created on Goliath server, yay!"
|
14
|
+
puts model.inspect
|
15
|
+
end
|
16
|
+
end
|
data/lib/untied/version.rb
CHANGED
data/lib/untied.rb
CHANGED
@@ -1,20 +1,5 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
require 'untied/version'
|
3
3
|
|
4
|
-
require 'rubygems'
|
5
|
-
require 'bundler/setup'
|
6
|
-
require 'amqp/utilities/event_loop_helper'
|
7
|
-
|
8
4
|
module Untied
|
9
|
-
def self.start
|
10
|
-
Thread.abort_on_exception = false
|
11
|
-
|
12
|
-
AMQP::Utilities::EventLoopHelper.run do
|
13
|
-
AMQP.start
|
14
|
-
end
|
15
|
-
|
16
|
-
EventMachine.next_tick do
|
17
|
-
AMQP.channel ||= AMQP::Channel.new(AMQP.connection)
|
18
|
-
end
|
19
|
-
end
|
20
5
|
end
|
data/untied.gemspec
CHANGED
@@ -18,8 +18,7 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.require_paths = ["lib"]
|
19
19
|
|
20
20
|
gem.add_development_dependency "rake"
|
21
|
-
gem.add_runtime_dependency "amqp"
|
22
21
|
|
23
|
-
gem.add_runtime_dependency "untied-consumer"
|
24
|
-
gem.add_runtime_dependency "untied-publisher"
|
22
|
+
gem.add_runtime_dependency "untied-consumer", "~> 0.0.4"
|
23
|
+
gem.add_runtime_dependency "untied-publisher", "~> 0.0.4"
|
25
24
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: untied
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Guilherme Cavalcanti
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-11-06 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|
@@ -35,44 +35,34 @@ dependencies:
|
|
35
35
|
version_requirements: &id002 !ruby/object:Gem::Requirement
|
36
36
|
none: false
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
hash:
|
40
|
+
hash: 23
|
41
41
|
segments:
|
42
42
|
- 0
|
43
|
-
|
43
|
+
- 0
|
44
|
+
- 4
|
45
|
+
version: 0.0.4
|
44
46
|
prerelease: false
|
45
47
|
type: :runtime
|
46
|
-
name:
|
48
|
+
name: untied-consumer
|
47
49
|
requirement: *id002
|
48
50
|
- !ruby/object:Gem::Dependency
|
49
51
|
version_requirements: &id003 !ruby/object:Gem::Requirement
|
50
52
|
none: false
|
51
53
|
requirements:
|
52
|
-
- -
|
54
|
+
- - ~>
|
53
55
|
- !ruby/object:Gem::Version
|
54
|
-
hash:
|
56
|
+
hash: 23
|
55
57
|
segments:
|
56
58
|
- 0
|
57
|
-
version: "0"
|
58
|
-
prerelease: false
|
59
|
-
type: :runtime
|
60
|
-
name: untied-consumer
|
61
|
-
requirement: *id003
|
62
|
-
- !ruby/object:Gem::Dependency
|
63
|
-
version_requirements: &id004 !ruby/object:Gem::Requirement
|
64
|
-
none: false
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
hash: 3
|
69
|
-
segments:
|
70
59
|
- 0
|
71
|
-
|
60
|
+
- 4
|
61
|
+
version: 0.0.4
|
72
62
|
prerelease: false
|
73
63
|
type: :runtime
|
74
64
|
name: untied-publisher
|
75
|
-
requirement: *
|
65
|
+
requirement: *id003
|
76
66
|
description: Cross application ActiveRecord::Observer
|
77
67
|
email:
|
78
68
|
- guiocavalcanti@gmail.com
|
@@ -91,6 +81,11 @@ files:
|
|
91
81
|
- README.md
|
92
82
|
- Rakefile
|
93
83
|
- bin/untied_worker
|
84
|
+
- examples/consumer-daemon/.rvmrc
|
85
|
+
- examples/consumer-daemon/Gemfile
|
86
|
+
- examples/consumer-daemon/README.mkd
|
87
|
+
- examples/consumer-daemon/consumerd.rb
|
88
|
+
- examples/consumer-daemon/observer.rb
|
94
89
|
- examples/goliath/.rvmrc
|
95
90
|
- examples/goliath/Gemfile
|
96
91
|
- examples/goliath/README.mkd
|