-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
89 changed files
with
2,587 additions
and
525 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
Feature: Routing observed data without matching tags | ||
|
||
In order to use Observed when the user's user-case is too simple that even tags are not needed | ||
I want to write configs with reporters which have no regexp patterns to match observed data | ||
|
||
Scenario: Create a .rb file containing Observed configuration and run it with the observed-oneshot command | ||
Given a file named "test.rb" with: | ||
""" | ||
require 'observed' | ||
include Observed | ||
class Test < Observed::Observer | ||
plugin_name 'test' | ||
def observe | ||
system.report(tag, {foo:1}) | ||
end | ||
end | ||
observe_then_report = (observe 'foo', via: 'test') | ||
.then(report via: 'stdout') | ||
observe_then_report.now | ||
""" | ||
When I run `ruby test.rb` | ||
Then the output should contain: | ||
""" | ||
{:foo=>1} | ||
""" | ||
Then the output should not contain: | ||
""" | ||
Error | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
integrations/observed-clockwork/lib/observed/clockwork/version.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module Observed | ||
module Clockwork | ||
VERSION = "0.1.0" | ||
VERSION = "0.2.0" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
*.gem | ||
*.rbc | ||
.bundle | ||
.config | ||
.yardoc | ||
Gemfile.lock | ||
InstalledFiles | ||
_yardoc | ||
coverage | ||
doc/ | ||
lib/bundler/man | ||
pkg | ||
rdoc | ||
spec/reports | ||
test/tmp | ||
test/version_tmp | ||
tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
source 'https://rubygems.org' | ||
|
||
# Specify your gem's dependencies in observed-eventmachine.gemspec | ||
gemspec | ||
|
||
group :development, :test do | ||
gem 'observed' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Copyright (c) 2013 GREE, Inc. | ||
|
||
MIT License | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Observed::Eventmachine | ||
|
||
A simple, experimental integration of Observed and EventMachine. | ||
|
||
## Installation | ||
|
||
Add this line to your application's Gemfile: | ||
|
||
gem 'observed-eventmachine' | ||
|
||
And then execute: | ||
|
||
$ bundle | ||
|
||
Or install it yourself as: | ||
|
||
$ gem install observed-eventmachine | ||
|
||
## Usage | ||
|
||
See examples under "examples/" and the cucumber tests under "features". | ||
|
||
## Contributing | ||
|
||
1. Fork it | ||
2. Create your feature branch (`git checkout -b my-new-feature`) | ||
3. Commit your changes (`git commit -am 'Add some feature'`) | ||
4. Push to the branch (`git push origin my-new-feature`) | ||
5. Create new Pull Request |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require "bundler/gem_tasks" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require 'observed' | ||
require 'observed/eventmachine' | ||
|
||
include Observed | ||
|
||
# This is a observed-eventmachine specific code to extend the DSL to use EventMachine | ||
extend Observed::EM | ||
|
||
class Test < Observed::Observer | ||
plugin_name 'test' | ||
def observe | ||
puts "Sleeping 10 seconds" | ||
sleep 10.0 | ||
puts "Slept 10 seconds" | ||
[tag, {foo:1}] | ||
end | ||
end | ||
|
||
observe 'foo', via: 'test' | ||
|
||
report /foo/, via: 'stdout', with: { | ||
format: -> _, _, data { "#{data}" } | ||
} | ||
|
||
# This is a observed-eventmachine specific code to schedule the observation on 'foo' | ||
every 1, run: 'foo' | ||
|
||
# This is a observed-eventmachine specific code to start running observations periodically, until we stop that by | ||
# sending signals | ||
start |
48 changes: 48 additions & 0 deletions
48
integrations/observed-eventmachine/features/integration_via_single_ruby_source.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
Feature: Integration via single Ruby source | ||
|
||
In order to easily integrate Observed with EventMachine, | ||
I want to extend Observed's DSL with words specific to the EventMachine integration, | ||
and make it runnable and testable in single Ruby source. | ||
|
||
Scenario: Create a .rb file containing Observed code and run it with the ruby command | ||
Given a file named "test.rb" with: | ||
""" | ||
require 'observed' | ||
require 'observed/eventmachine' | ||
include Observed | ||
extend Observed::EM | ||
$count = 0 | ||
class Test < Observed::Observer | ||
plugin_name 'test' | ||
def observe | ||
$count += 1 | ||
system.report(tag, {foo:1}) | ||
if $count >= 2 | ||
Thread.start { | ||
sleep 1 | ||
exit | ||
} | ||
end | ||
end | ||
end | ||
observe 'foo', via: 'test' | ||
report /foo/, via: 'stdout', with: { | ||
format: -> tag, _, data { "#{tag} #{$count} #{data}" } | ||
} | ||
every 1, run: 'foo' | ||
start | ||
""" | ||
When I run `ruby test.rb` | ||
Then the output should contain: | ||
""" | ||
foo 1 {:foo=>1} | ||
foo 2 {:foo=>1} | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib') | ||
require 'aruba/cucumber' | ||
|
||
World(Aruba::Api) | ||
|
||
Before do | ||
@aruba_timeout_seconds = 120 | ||
end |
70 changes: 70 additions & 0 deletions
70
integrations/observed-eventmachine/lib/observed/eventmachine.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
require "eventmachine" | ||
require "observed/eventmachine/version" | ||
|
||
module Observed | ||
module EM | ||
|
||
# Schedule the observation to run it periodically | ||
# @param [Float|Fixnum] seconds | ||
# @param [Hash] args | ||
# @option args [String] :run The tag of the observation to schedule running. It is the one registered via the code | ||
# `observe tag, via: 'observer_plugin_name'`. | ||
def every(seconds, args) | ||
@builder.every seconds, args | ||
end | ||
|
||
# Start EventMachine and run scheduled observations. | ||
def start | ||
::EM.run do | ||
Signal.trap("INT") { ::EventMachine.stop } | ||
Signal.trap("TERM") { ::EventMachine.stop } | ||
@builder.periodic_tasks.each do |periodic_task| | ||
::EM.add_periodic_timer(periodic_task.seconds) do | ||
::EM.defer { run(periodic_task.tag) } | ||
end | ||
end | ||
end | ||
end | ||
|
||
# Automatically called on `extend Observed::EM` | ||
def init_observed_em_builder | ||
@builder = Builder.new | ||
end | ||
|
||
def self.extended(klass) | ||
klass.init_observed_em_builder | ||
end | ||
|
||
class Builder | ||
|
||
# Schedule the observation to run it periodically. | ||
# Scheduled observations can be obtained later by calling the method `periodic_tasks`. | ||
# @param [Float|Fixnum] seconds The interval to run the observation, in seconds. | ||
# @param [Hash] args | ||
# @option args [String] :run The tag of the observation to schedule running. It is the one registered via the code | ||
# `observe tag, via: 'observer_plugin_name'`. | ||
def every(seconds, args) | ||
periodic_tasks << PeriodicTask.new(seconds, args) | ||
end | ||
|
||
def periodic_tasks | ||
@periodic_tasks ||= [] | ||
end | ||
end | ||
|
||
class PeriodicTask | ||
attr_reader :seconds | ||
attr_reader :args | ||
|
||
def initialize(seconds, args) | ||
@seconds = seconds | ||
@args = args | ||
end | ||
|
||
def tag | ||
args[:run] | ||
end | ||
end | ||
|
||
end | ||
end |
5 changes: 5 additions & 0 deletions
5
integrations/observed-eventmachine/lib/observed/eventmachine/version.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module Observed | ||
module EM | ||
VERSION = "0.2.0" | ||
end | ||
end |
Oops, something went wrong.