observed 0.1.1 → 0.2.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +9 -9
  2. data/.travis.yml +4 -0
  3. data/README.md +53 -78
  4. data/examples/observed.rb +1 -1
  5. data/exe/observed-oneshot +3 -1
  6. data/features/explicit_routing.feature +33 -0
  7. data/features/oneshot.feature +4 -0
  8. data/features/test_in_single_ruby_source.feature +4 -0
  9. data/integrations/observed-clockwork/features/run_observed_inside_clockwork.feature +6 -7
  10. data/integrations/observed-clockwork/lib/observed/clockwork/version.rb +1 -1
  11. data/integrations/observed-clockwork/lib/observed/clockwork.rb +0 -1
  12. data/integrations/observed-clockwork/observed-clockwork.gemspec +1 -1
  13. data/integrations/observed-eventmachine/.gitignore +17 -0
  14. data/integrations/observed-eventmachine/Gemfile +8 -0
  15. data/integrations/observed-eventmachine/LICENSE.txt +22 -0
  16. data/integrations/observed-eventmachine/README.md +29 -0
  17. data/integrations/observed-eventmachine/Rakefile +1 -0
  18. data/integrations/observed-eventmachine/examples/observed.rb +30 -0
  19. data/integrations/observed-eventmachine/features/integration_via_single_ruby_source.feature +48 -0
  20. data/integrations/observed-eventmachine/features/support/env.rb +8 -0
  21. data/integrations/observed-eventmachine/lib/observed/eventmachine/version.rb +5 -0
  22. data/integrations/observed-eventmachine/lib/observed/eventmachine.rb +70 -0
  23. data/integrations/observed-eventmachine/observed-eventmachine.gemspec +28 -0
  24. data/lib/observed/application/oneshot.rb +14 -37
  25. data/lib/observed/builtin_plugins/file.rb +5 -14
  26. data/lib/observed/builtin_plugins/stdout.rb +7 -14
  27. data/lib/observed/config.rb +4 -4
  28. data/lib/observed/config_builder.rb +154 -87
  29. data/lib/observed/config_dsl.rb +2 -8
  30. data/lib/observed/configurable.rb +61 -3
  31. data/lib/observed/context.rb +90 -0
  32. data/lib/observed/default/observer.rb +2 -5
  33. data/lib/observed/default.rb +0 -1
  34. data/lib/observed/event_bus.rb +31 -0
  35. data/lib/observed/execution_job_factory.rb +95 -0
  36. data/lib/observed/job.rb +163 -0
  37. data/lib/observed/jobbed_event_bus.rb +33 -0
  38. data/lib/observed/logging.rb +40 -0
  39. data/lib/observed/observer.rb +1 -0
  40. data/lib/observed/observer_helpers/timer.rb +13 -5
  41. data/lib/observed/pluggable.rb +11 -0
  42. data/lib/observed/reporter/regexp_matching.rb +2 -1
  43. data/lib/observed/reporter/report_formatting.rb +57 -0
  44. data/lib/observed/reporter.rb +0 -2
  45. data/lib/observed/system.rb +11 -78
  46. data/lib/observed/translator.rb +22 -0
  47. data/lib/observed/version.rb +1 -1
  48. data/lib/observed.rb +10 -12
  49. data/omnibus-observed/.gitignore +9 -0
  50. data/omnibus-observed/Berksfile +3 -0
  51. data/omnibus-observed/Berksfile.lock +52 -0
  52. data/omnibus-observed/Gemfile +4 -0
  53. data/omnibus-observed/README.md +102 -0
  54. data/omnibus-observed/Vagrantfile +93 -0
  55. data/omnibus-observed/config/projects/observed.rb +20 -0
  56. data/omnibus-observed/config/software/observed.rb +19 -0
  57. data/omnibus-observed/package-scripts/observed/makeselfinst +27 -0
  58. data/omnibus-observed/package-scripts/observed/postinst +17 -0
  59. data/omnibus-observed/package-scripts/observed/postrm +9 -0
  60. data/plugins/observed-fluentd/lib/observed/fluentd/version.rb +1 -1
  61. data/plugins/observed-gauge/README.md +5 -0
  62. data/plugins/observed-gauge/lib/observed/gauge/version.rb +1 -1
  63. data/plugins/observed-gauge/lib/observed/gauge.rb +11 -13
  64. data/plugins/observed-gauge/observed-gauge.gemspec +1 -1
  65. data/plugins/observed-gauge/spec/gauge_spec.rb +7 -7
  66. data/plugins/observed-growl/Gemfile +6 -0
  67. data/plugins/observed-growl/lib/observed/growl.rb +80 -0
  68. data/plugins/observed-http/lib/observed/http/version.rb +1 -1
  69. data/plugins/observed-http/lib/observed/http.rb +10 -8
  70. data/plugins/observed-http/observed-http.gemspec +1 -1
  71. data/plugins/observed-http/spec/http_spec.rb +62 -7
  72. data/plugins/observed-http/spec/integration_spec.rb +14 -0
  73. data/plugins/observed-shell/Gemfile +5 -0
  74. data/plugins/observed-shell/lib/observed/shell.rb +54 -0
  75. data/run-integration-tests +81 -0
  76. data/spec/builtin_plugins/stdout_spec.rb +7 -3
  77. data/spec/config_builder_spec.rb +42 -59
  78. data/spec/config_dsl_spec.rb +4 -0
  79. data/spec/configurable_spec.rb +141 -31
  80. data/spec/event_bus_spec.rb +16 -0
  81. data/spec/execution_job_factory_spec.rb +35 -0
  82. data/spec/job_factory_spec.rb +16 -0
  83. data/spec/job_spec.rb +228 -0
  84. data/spec/jobbed_event_bus_spec.rb +38 -0
  85. data/spec/observed_spec.rb +203 -0
  86. data/spec/observer_helpers/timer_spec.rb +187 -0
  87. data/spec/oneshot_spec.rb +7 -2
  88. data/spec/system_spec.rb +5 -39
  89. metadata +55 -12
  90. data/lib/observed/default/reporter.rb +0 -17
  91. data/lib/observed/reader.rb +0 -14
  92. data/lib/observed/writer.rb +0 -14
  93. data/spec/reader_spec.rb +0 -15
  94. data/spec/writer_spec.rb +0 -16
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZjY4MTNiYmFjYTdiNmQ3ODk3ZThkOGRjMjNkNWI1MDg2MmZhYTUxNw==
4
+ ZjAzODY3YWFkYmE3ZWM3MGFmYzkzY2Y4ZjI4MTExNmQyYjRmZTJjOQ==
5
5
  data.tar.gz: !binary |-
6
- YzYwZWI3NGE3ZmI4MmQ4NDRkZWZkMTBiNzU2NDM5NmUzMzg3ZWZiYQ==
7
- !binary "U0hBNTEy":
6
+ YzdlNTAyYWNmNzZmNWNlODNmYTA0MDY4ZjFjM2RlMWFlNTFhNjFlMw==
7
+ SHA512:
8
8
  metadata.gz: !binary |-
9
- NGM5N2Q4ODQzMTRlZDMzNzdiN2UwODVjNmE0NzUwMjdkZTU2MzdkOThjNjc3
10
- NmQwMjRkZGIzYzM0ZDA3N2FkMWVkZmY0YjAyNDE3MWNjMjMxMDUwYmY5ZmMw
11
- MWNkMjFmN2RiMTY2Mzg1MjRmMzVlOWEwMGM0MDAxZjE5N2UyOTg=
9
+ Y2UzMWZiYjliOGE0MDRiMGVhZTE1ZGExOWQzNzBjYjU5YzM4MDM3OWE0MWRh
10
+ OWJjYWRlNDc5YjhjMGRmNTY1NGI0Yzg0MWMxY2Q1NjdjZjA1MGZjNjYzODU0
11
+ MDA1ZGM4MjE5MDQzYTMxNWYwNjExYzYzMmUyOTFkYzBjNzFlYTM=
12
12
  data.tar.gz: !binary |-
13
- MTYxNDc0NGRlZjE2NDkwMzNmOGY5ZTM4MDQ1NmNkZWJkNTY0NDk0MWY4MDkz
14
- OWQ2ZjQ1MzVhYTQyNDE2MGU4YjExZDEyNTg3ZDg1ZDBmM2NlMWViMjBlZjdi
15
- YzQ0MWE5OThlMDc1ZmVmMGZkMTQ5YTAxM2QxNTg4NWU4ZGIyYzQ=
13
+ NTZhM2U0Nzg3M2ViMjMzNDM1NTI3YTZlOTUwOWE1NDk0OGNiMGM3Y2MwNWVi
14
+ MGZhOTZkY2YxMzBkYzZhNWJhM2M2MmQyMWFjYzE2YWY3YTRmM2Y2ZGViYjEx
15
+ ZDg5YzM5YmQzZTY4MDg0NTE3YTJlNTRhNWMwNTAzOGYzYWUxNmY=
data/.travis.yml CHANGED
@@ -9,3 +9,7 @@ matrix:
9
9
  exclude:
10
10
  - rvm: 1.9.3
11
11
  jdk: openjdk7
12
+ allow_failures:
13
+ - rvm: jruby-19mode
14
+ script: ./run-integration-tests
15
+ before_install: sudo apt-get install librrd-dev
data/README.md CHANGED
@@ -1,67 +1,45 @@
1
- # [Observed](https://github.com/gree/observed)
1
+ # Observed
2
2
 
3
- A polling framework
3
+ [![Build Status](https://travis-ci.org/gree/observed.png?branch=master)](https://travis-ci.org/gree/observed) [![Coverage Status](https://coveralls.io/repos/gree/observed/badge.png?branch=master)](https://coveralls.io/r/gree/observed?branch=master) [![Code Climate](https://codeclimate.com/github/gree/observed.png)](https://codeclimate.com/github/gree/observed)
4
4
 
5
- [Observed](https://github.com/gree/observed) is a framework for polling various applications/middlewares/services running locally or on remote servers like
6
- ones in your production environment.
7
- It is designed with extensibility in mind.
5
+ Observed is a highly extensible framework for polling applications, middlewares and services running locally or on remote servers.
8
6
 
9
7
  -----
10
8
 
11
- Observed polls services, optionally transforms the results, and then redirects the results to another services.
12
- Observed is open for extension which means that it is extensible via plugins to support add more services and transformations.
9
+ Observed allows you to:
13
10
 
14
- To be clear, you can use Observed to:
11
+ 1. poll server(s),
12
+ 2. optionally modify the response result,
13
+ 3. pass the result on to other services or trigger other tasks
15
14
 
16
- 1. poll something,
17
- 2. optionally transform the result,
18
- 3. pass the result to another services or trigger something
15
+ All the above 3 operations are extensible via plugins and can be configured via configuration files.
19
16
 
20
- All the three things mentioned above can be extended via plugins and configured via configuration files.
21
-
22
- There are known plugins for:
17
+ There are plugins available for:
23
18
 
24
19
  - Polling HTTP-based services to detect failures and performance degradation
25
20
  - Sending observed data to Fluentd
26
- - (More to come)
27
-
28
- Observed has has a very small code-base (only a few hundreds of lines) and it should not be too hard to understand the
29
- code and develop plugins.
30
21
 
31
- Observed's extensible design through plugins is inspired by other Ruby products like Fluentd,
32
- and having knowledge of other Ruby products may help understanding Observed.
33
- (But remember that Observed is yet a highly ambitioned and experimental framework. Observed's code has more space to
34
- improve than other great Ruby products.)
22
+ Additional plugins will be released in the future.
35
23
 
36
- Observed is (and its plugins should be) stateless.
37
- Specially for Observed, this means that it should work similarly when it is ran as a daemon or a _oneshot_ application like
38
- a regular cron job as states are stored somewhere outside of the application instance.
24
+ Observed has has a very small code-base (only a few hundred lines) which makes reading and understanding it's source code and developing plugins for it a relatively simple task.
39
25
 
40
- Observed is intended to work on Ruby 1.9.3 but should work on Ruby 2.0+ too.
26
+ Observed's extensible design through plugins is inspired by other Ruby projects such as Fluentd. People familiar with other Ruby products should feel right at home with Observed. As of now it is a highly ambitious and experimental framework with big potential for growth and improvements.
41
27
 
42
- ## What it is not
28
+ Observed is (and its plugins should be) stateless.
29
+ This means that it should work in the same manner whether it is run as a daemon or a _oneshot_ application like
30
+ a regular cron job, as states should be stored outside of the application instance with regards to Observed.
43
31
 
44
- Observed is:
32
+ Observed is intended to be run on Ruby 1.9.3 but should work on Ruby 2.0+ too.
45
33
 
46
- - Not a framework for creating Web-based polls which are voted. It's all about [polling (computer science)](http://en.wikipedia.org/wiki/Polling_\(computer_science\))
47
- - Not a monitoring and reporting tool like Ganglia, New Relic, or etc.
48
- But Observed can be used to gather simple metrics via its plugins, and it can pass those metrics to an another tool to
49
- achieve any serious monitoring or reporting.
50
- - Not a log collector like Fluentd.
51
- Observed can be used to emit event logs to the log collector of your choice, but it does not replace or act like that.
52
- - Not a [job scheduler](http://en.wikipedia.org/wiki/Job_scheduler) like cron, though it can be integrated to those schedulers to make them trigger Observed to do the
53
- job.
34
+ ## Observed is not:
35
+ - a monitoring and reporting tool such as New Relic etc. However, Observed can be used for collecting simple metrics via plugins, then pass them on to another full-fledged monitoring or reporting tool.
36
+ - a log collector like Fluentd. Observed can be used to emit event logs to the log collector of your choice, but it does not replace the log collector.
37
+ - a [job scheduler](http://en.wikipedia.org/wiki/Job_scheduler) (e.g. cron), though it can be integrated with job schedulers to make them trigger Observed to perform jobs.
54
38
 
55
39
  ## Similar products
56
40
 
57
- - [vacuumetrix](https://github.com/99designs/vacuumetrix) gets metrics from various sources and puts those to various
58
- outputs like Graphite, Ganglia, etc.
59
- On the other hand, Observed scope itself to be used just for `polling` and also it outputs to not only monitoring
60
- systems but any system.
61
- - [metrics-sampler](https://github.com/dimovelev/metrics-sampler) is a java program which queries metrics from various
62
- sources and sends them to outputs like the console or Graphite. It supports inputs such as JMX, JDBC, apache-status,
63
- Oracle NoSQL, Redis, webmethods, or regular process which is runnable via the command-line and is able to communiate
64
- via standard input/output.
41
+ - [vacuumetrix](https://github.com/99designs/vacuumetrix) - Collects metrics from various sources and outputs them to various destinations (e.g Graphite). Observed only covers the `polling` part, but can output to not just monitoring systems but any system.
42
+ - [metrics-sampler](https://github.com/dimovelev/metrics-sampler) - A Java program which queries metrics from various sources and outputs to various destinations such as Graphite or consoles. It supports various methods of input such as JMX, JDBC, apache-status, Oracle NoSQL, Redis, web API, or regular processes which are executable via the command-line, and is able to communicate via standard input/output.
65
43
 
66
44
  ## Installation
67
45
 
@@ -73,7 +51,7 @@ And then execute:
73
51
 
74
52
  $ bundle
75
53
 
76
- Or install it yourself as:
54
+ Or install it yourself with:
77
55
 
78
56
  $ gem install observed
79
57
 
@@ -83,24 +61,23 @@ Or `git clone` the sources and install by using rake:
83
61
 
84
62
  ## Usage
85
63
 
86
- Just for the purpose of illustration, _let Observed observe and report the healthiness of Google_.
64
+ Simple example: _use Observed to observe and report the healthiness of Google_.
87
65
 
88
- Observed itself is just a framework and doesn't support any service by default.
89
- Now, just for example, let's assume that we want Observed to poll our HTTP-based webs service and report the result and
90
- show average response time.
91
- We start with installing some observed plugins:
66
+ Assume that we want Observed to poll a HTTP-based web service (Google) and report the results.
67
+
68
+ Since Observed by itself is just a framework and by default does not have built-in support for any service, we start by installing some Observed plugins:
92
69
 
93
70
  $ gem install observed
94
71
  $ gem install observed-clockwork
95
72
  $ gem install observed-http
96
73
 
97
- In this case, we use observed-clockwork to trigger polls through [Clockwork](https://github.com/tomykaira/clockwork).
98
- observed-clockwork is a library intended to use in Clockwork's configuration
99
- file. Clockwork is a scheduler process made with Ruby, which is intended to replace cron.
100
- Note that we can just use cron which is supported via observed-cron plugin(or even without the plugin, it is breeze to use
101
- Observed with cron) but we proceed with Clockwork just for example.
74
+ For this example, we will use observed-clockwork to trigger polls through [Clockwork](https://github.com/tomykaira/clockwork).
75
+
76
+ observed-clockwork is a library to be used with Clockwork's configuration file. Clockwork is a cron replacement for a scheduler process that is written in Ruby.
77
+
78
+ Note that we can also use cron, which is supported via observed-cron plugin (even without the plugin it is really simple to use Observed with cron) but we will use Clockwork for this example.
102
79
 
103
- With `clockwork.rb` like:
80
+ Edit the contents of `clockwork.rb`:
104
81
 
105
82
  ```ruby
106
83
  require 'pathname'
@@ -110,18 +87,17 @@ require 'observed/clockwork'
110
87
 
111
88
  include Clockwork
112
89
 
113
- # Below two lines are specific to Observed's Clockwork support.
114
- # Others lines are just standard `clockwork.rb`
115
- include Observed::Clockwork
116
-
117
90
  the_dir = Pathname.new(File.dirname(__FILE__))
118
91
 
92
+ # The following two lines are specific to Observed's Clockwork support.
93
+ include Observed::Clockwork
94
+
119
95
  register_observed_handler :config_file => the_dir + 'observed.rb'
120
96
 
121
97
  every(10.seconds, 'google.health')
122
98
  ```
123
99
 
124
- With `observed.rb` like:
100
+ Edit the contents of `observed.rb` as follows:
125
101
 
126
102
  ```ruby
127
103
  require 'observed/http'
@@ -143,10 +119,10 @@ report /google.health/, via: 'stdout', with: {
143
119
  }
144
120
  ```
145
121
 
146
- As you see, `observed.conf` is just a Ruby source to describe Observed's configuration.
147
- You can rely on Ruby's language features, gems, or etc.
122
+ As you see, `observed.rb` is just a Ruby source file that describes Observed's configuration.
123
+ You can use Ruby language's features, gems, etc.
148
124
 
149
- We have finished configuring Observed.
125
+ That sums up the configuration part of things.
150
126
 
151
127
  Now, run:
152
128
 
@@ -161,35 +137,34 @@ Google is healthy! (^o^)
161
137
  ...
162
138
  ```
163
139
 
164
- You did it!
165
- You just saw that Google's healthiness is printed to the standard output every 10 seconds.
166
- In other words, you did observed Google's healthiness with easily with Observed.
140
+ And we're done! That's all it takes to print Google's health to standard output every 10 seconds with Observed.
167
141
 
168
- The example described here is fairly simple and would look useless at a glance, but remember that Observed is just a
169
- framework.
170
- If you want to monitor performances or get statistics on performance on your service, you can redirect the results to
171
- Fluentd, Ganglia or else and take advantages of their rich features and plugins.
172
- We like not reinventing the wheel and it is encouraged to use Observed for just to poll something and then emit the
173
- result to other services. Things like monitoring, watching, alerting can be done there.
142
+ The example described here is fairly simple and may look useless at first glance, but keep in mind that Observed is just a framework.
143
+
144
+ If you want to monitor performance or get statistics on performance on your service, you can redirect the results to Fluentd or other service to take advantage of their features and plugins.
145
+
146
+ We prefer to not reinvent the wheel and encourage people to use Observed for polling and output results to other services for other tasks like monitoring or alerts.
174
147
 
175
148
  ## Documentation
176
149
 
177
150
  Observed is documented with [YARD](https://github.com/lsegal/yard).
178
- The documentation is not currently hosted on any server and we have to build the document before reading it.
179
151
 
180
- To generate the document, install YARD:
152
+ The latest documentation for the master branch of Observed [is available at rubydoc.info](http://rubydoc.info/github/gree/observed).
153
+
154
+ You can also generate the document locally.
155
+ To do so, install YARD:
181
156
 
182
157
  ```
183
158
  $ gem install yard
184
159
  ```
185
160
 
186
- And then run `yardoc` like:
161
+ And then run `yardoc` as follows:
187
162
 
188
163
  ```
189
164
  $ yardoc 'lib/**/*.rb'
190
165
  ```
191
166
 
192
- Open the document:
167
+ You can then open the generated documentation:
193
168
 
194
169
  ```
195
170
  $ open doc/index.html
@@ -201,4 +176,4 @@ $ open doc/index.html
201
176
  2. Create your feature branch (`git checkout -b my-new-feature`)
202
177
  3. Commit your changes (`git commit -am 'Add some feature'`)
203
178
  4. Push to the branch (`git push origin my-new-feature`)
204
- 5. Create new Pull Request
179
+ 5. Create a new pull request
data/examples/observed.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  class Test < Observed::Observer
2
2
  plugin_name 'test'
3
3
  def observe
4
- system.report(tag, {foo:1})
4
+ [tag, {foo:1}]
5
5
  end
6
6
  end
7
7
 
data/exe/observed-oneshot CHANGED
@@ -4,7 +4,9 @@ require 'observed'
4
4
  require 'observed/application/oneshot'
5
5
 
6
6
  begin
7
- Observed::Application::Oneshot.from_argv(ARGV).run
7
+ argv = ARGV.dup
8
+ args = Observed::Application::Oneshot.parse_argv!(argv)
9
+ Observed::Application::Oneshot.create(args).run *argv
8
10
  rescue Observed::Application::Oneshot::InvalidArgumentError => e
9
11
  $stderr.puts 'Missing the path to a Observed config file'
10
12
  $stderr.puts 'Usage: observed-oneshot [-d|--debug] [-l LOG_FILE|--log_file LOG_FILE] <observed.rb>'
@@ -0,0 +1,33 @@
1
+ Feature: Routing observed data without matching tags
2
+
3
+ In order to use Observed when the user's user-case is too simple that even tags are not needed
4
+ I want to write configs with reporters which have no regexp patterns to match observed data
5
+
6
+ Scenario: Create a .rb file containing Observed configuration and run it with the observed-oneshot command
7
+ Given a file named "test.rb" with:
8
+ """
9
+ require 'observed'
10
+
11
+ include Observed
12
+
13
+ class Test < Observed::Observer
14
+ plugin_name 'test'
15
+ def observe
16
+ system.report(tag, {foo:1})
17
+ end
18
+ end
19
+
20
+ observe_then_report = (observe 'foo', via: 'test')
21
+ .then(report via: 'stdout')
22
+
23
+ observe_then_report.now
24
+ """
25
+ When I run `ruby test.rb`
26
+ Then the output should contain:
27
+ """
28
+ {:foo=>1}
29
+ """
30
+ Then the output should not contain:
31
+ """
32
+ Error
33
+ """
@@ -22,3 +22,7 @@ Feature: Be testable in a single command
22
22
  """
23
23
  foo {:foo=>1}
24
24
  """
25
+ Then the output should not contain:
26
+ """
27
+ Error
28
+ """
@@ -30,3 +30,7 @@ Feature: Be testable in a single Ruby source
30
30
  """
31
31
  foo {:foo=>1}
32
32
  """
33
+ Then the output should not contain:
34
+ """
35
+ Error
36
+ """
@@ -26,12 +26,11 @@ Feature: Running Observed inside Clockwork
26
26
  def observe
27
27
  sleep_duration = rand / 20
28
28
  sleep sleep_duration
29
- system.report(tag, "Foo #{sleep_duration}")
30
-
31
- # For testing purpose,
32
- # we want the `clockwork` process to exit as soon as we ran Observed to report the test
33
- # output to the stdout
34
- exit
29
+ ::Thread.start {
30
+ sleep 1
31
+ exit
32
+ }
33
+ system.report(tag, {text: "Foo #{sleep_duration}"})
35
34
  end
36
35
 
37
36
  def logger
@@ -55,5 +54,5 @@ Feature: Running Observed inside Clockwork
55
54
  When I run `clockwork clockwork.rb`
56
55
  Then the output should contain:
57
56
  """
58
- foo_1 Foo
57
+ 00 foo_1 {:text=>"Foo
59
58
  """
@@ -1,5 +1,5 @@
1
1
  module Observed
2
2
  module Clockwork
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0.rc1"
4
4
  end
5
5
  end
@@ -10,7 +10,6 @@ module Observed
10
10
  def register_observed_handler(args)
11
11
  Observed.init!
12
12
  Observed.configure args
13
- Observed.load! args[:config_file]
14
13
  ::Clockwork.handler do |job|
15
14
  Observed.run job
16
15
  end
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.add_dependency 'clockwork'
23
23
  spec.add_dependency 'daemons'
24
- spec.add_dependency 'observed', "~> 0.1.0"
24
+ spec.add_dependency 'observed', "~> 0.2.0.rc1"
25
25
  spec.add_development_dependency "bundler", "~> 1.3"
26
26
  spec.add_development_dependency "rake"
27
27
  spec.add_development_dependency "cucumber"
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in observed-eventmachine.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem 'observed'
8
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 GREE, Inc.
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Observed::Eventmachine
2
+
3
+ A simple, experimental integration of Observed and EventMachine.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'observed-eventmachine'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install observed-eventmachine
18
+
19
+ ## Usage
20
+
21
+ See examples under "examples/" and the cucumber tests under "features".
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,30 @@
1
+ require 'observed'
2
+ require 'observed/eventmachine'
3
+
4
+ include Observed
5
+
6
+ # This is a observed-eventmachine specific code to extend the DSL to use EventMachine
7
+ extend Observed::EM
8
+
9
+ class Test < Observed::Observer
10
+ plugin_name 'test'
11
+ def observe
12
+ puts "Sleeping 10 seconds"
13
+ sleep 10.0
14
+ puts "Slept 10 seconds"
15
+ [tag, {foo:1}]
16
+ end
17
+ end
18
+
19
+ observe 'foo', via: 'test'
20
+
21
+ report /foo/, via: 'stdout', with: {
22
+ format: -> _, _, data { "#{data}" }
23
+ }
24
+
25
+ # This is a observed-eventmachine specific code to schedule the observation on 'foo'
26
+ every 1, run: 'foo'
27
+
28
+ # This is a observed-eventmachine specific code to start running observations periodically, until we stop that by
29
+ # sending signals
30
+ start
@@ -0,0 +1,48 @@
1
+ Feature: Integration via single Ruby source
2
+
3
+ In order to easily integrate Observed with EventMachine,
4
+ I want to extend Observed's DSL with words specific to the EventMachine integration,
5
+ and make it runnable and testable in single Ruby source.
6
+
7
+ Scenario: Create a .rb file containing Observed code and run it with the ruby command
8
+ Given a file named "test.rb" with:
9
+ """
10
+ require 'observed'
11
+ require 'observed/eventmachine'
12
+
13
+ include Observed
14
+
15
+ extend Observed::EM
16
+
17
+ $count = 0
18
+
19
+ class Test < Observed::Observer
20
+ plugin_name 'test'
21
+ def observe
22
+ $count += 1
23
+ system.report(tag, {foo:1})
24
+ if $count >= 2
25
+ Thread.start {
26
+ sleep 1
27
+ exit
28
+ }
29
+ end
30
+ end
31
+ end
32
+
33
+ observe 'foo', via: 'test'
34
+
35
+ report /foo/, via: 'stdout', with: {
36
+ format: -> tag, _, data { "#{tag} #{$count} #{data}" }
37
+ }
38
+
39
+ every 1, run: 'foo'
40
+
41
+ start
42
+ """
43
+ When I run `ruby test.rb`
44
+ Then the output should contain:
45
+ """
46
+ foo 1 {:foo=>1}
47
+ foo 2 {:foo=>1}
48
+ """
@@ -0,0 +1,8 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
+ require 'aruba/cucumber'
3
+
4
+ World(Aruba::Api)
5
+
6
+ Before do
7
+ @aruba_timeout_seconds = 120
8
+ end
@@ -0,0 +1,5 @@
1
+ module Observed
2
+ module EM
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,70 @@
1
+ require "eventmachine"
2
+ require "observed/eventmachine/version"
3
+
4
+ module Observed
5
+ module EM
6
+
7
+ # Schedule the observation to run it periodically
8
+ # @param [Float|Fixnum] seconds
9
+ # @param [Hash] args
10
+ # @option args [String] :run The tag of the observation to schedule running. It is the one registered via the code
11
+ # `observe tag, via: 'observer_plugin_name'`.
12
+ def every(seconds, args)
13
+ @builder.every seconds, args
14
+ end
15
+
16
+ # Start EventMachine and run scheduled observations.
17
+ def start
18
+ ::EM.run do
19
+ Signal.trap("INT") { ::EventMachine.stop }
20
+ Signal.trap("TERM") { ::EventMachine.stop }
21
+ @builder.periodic_tasks.each do |periodic_task|
22
+ ::EM.add_periodic_timer(periodic_task.seconds) do
23
+ ::EM.defer { run(periodic_task.tag) }
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ # Automatically called on `extend Observed::EM`
30
+ def init_observed_em_builder
31
+ @builder = Builder.new
32
+ end
33
+
34
+ def self.extended(klass)
35
+ klass.init_observed_em_builder
36
+ end
37
+
38
+ class Builder
39
+
40
+ # Schedule the observation to run it periodically.
41
+ # Scheduled observations can be obtained later by calling the method `periodic_tasks`.
42
+ # @param [Float|Fixnum] seconds The interval to run the observation, in seconds.
43
+ # @param [Hash] args
44
+ # @option args [String] :run The tag of the observation to schedule running. It is the one registered via the code
45
+ # `observe tag, via: 'observer_plugin_name'`.
46
+ def every(seconds, args)
47
+ periodic_tasks << PeriodicTask.new(seconds, args)
48
+ end
49
+
50
+ def periodic_tasks
51
+ @periodic_tasks ||= []
52
+ end
53
+ end
54
+
55
+ class PeriodicTask
56
+ attr_reader :seconds
57
+ attr_reader :args
58
+
59
+ def initialize(seconds, args)
60
+ @seconds = seconds
61
+ @args = args
62
+ end
63
+
64
+ def tag
65
+ args[:run]
66
+ end
67
+ end
68
+
69
+ end
70
+ end