Skip to content

Commit

Permalink
Merge branch '0.2.0-release'
Browse files Browse the repository at this point in the history
  • Loading branch information
KUOKA Yusuke committed Feb 17, 2014
2 parents 6e300b0 + 3e0e1db commit 7c130d0
Show file tree
Hide file tree
Showing 89 changed files with 2,587 additions and 525 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ matrix:
exclude:
- rvm: 1.9.3
jdk: openjdk7
allow_failures:
- rvm: jruby-19mode
script: ./run-integration-tests
before_install: sudo apt-get install librrd-dev
2 changes: 1 addition & 1 deletion examples/observed.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Test < Observed::Observer
plugin_name 'test'
def observe
system.report(tag, {foo:1})
[tag, {foo:1}]
end
end

Expand Down
4 changes: 3 additions & 1 deletion exe/observed-oneshot
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ require 'observed'
require 'observed/application/oneshot'

begin
Observed::Application::Oneshot.from_argv(ARGV).run
argv = ARGV.dup
args = Observed::Application::Oneshot.parse_argv!(argv)
Observed::Application::Oneshot.create(args).run *argv
rescue Observed::Application::Oneshot::InvalidArgumentError => e
$stderr.puts 'Missing the path to a Observed config file'
$stderr.puts 'Usage: observed-oneshot [-d|--debug] [-l LOG_FILE|--log_file LOG_FILE] <observed.rb>'
Expand Down
33 changes: 33 additions & 0 deletions features/explicit_routing.feature
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
"""
4 changes: 4 additions & 0 deletions features/oneshot.feature
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ Feature: Be testable in a single command
"""
foo {:foo=>1}
"""
Then the output should not contain:
"""
Error
"""
4 changes: 4 additions & 0 deletions features/test_in_single_ruby_source.feature
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ Feature: Be testable in a single Ruby source
"""
foo {:foo=>1}
"""
Then the output should not contain:
"""
Error
"""
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ Feature: Running Observed inside Clockwork
def observe
sleep_duration = rand / 20
sleep sleep_duration
system.report(tag, "Foo #{sleep_duration}")
# For testing purpose,
# we want the `clockwork` process to exit as soon as we ran Observed to report the test
# output to the stdout
exit
::Thread.start {
sleep 1
exit
}
system.report(tag, {text: "Foo #{sleep_duration}"})
end
def logger
Expand All @@ -55,5 +54,5 @@ Feature: Running Observed inside Clockwork
When I run `clockwork clockwork.rb`
Then the output should contain:
"""
foo_1 Foo
00 foo_1 {:text=>"Foo
"""
1 change: 0 additions & 1 deletion integrations/observed-clockwork/lib/observed/clockwork.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module Clockwork
def register_observed_handler(args)
Observed.init!
Observed.configure args
Observed.load! args[:config_file]
::Clockwork.handler do |job|
Observed.run job
end
Expand Down
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
2 changes: 1 addition & 1 deletion integrations/observed-clockwork/observed-clockwork.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Gem::Specification.new do |spec|

spec.add_dependency 'clockwork'
spec.add_dependency 'daemons'
spec.add_dependency 'observed', "~> 0.1.0"
spec.add_dependency 'observed', "~> 0.2"
spec.add_development_dependency "bundler", "~> 1.3"
spec.add_development_dependency "rake"
spec.add_development_dependency "cucumber"
Expand Down
17 changes: 17 additions & 0 deletions integrations/observed-eventmachine/.gitignore
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
8 changes: 8 additions & 0 deletions integrations/observed-eventmachine/Gemfile
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
22 changes: 22 additions & 0 deletions integrations/observed-eventmachine/LICENSE.txt
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.
29 changes: 29 additions & 0 deletions integrations/observed-eventmachine/README.md
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
1 change: 1 addition & 0 deletions integrations/observed-eventmachine/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require "bundler/gem_tasks"
30 changes: 30 additions & 0 deletions integrations/observed-eventmachine/examples/observed.rb
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
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}
"""
8 changes: 8 additions & 0 deletions integrations/observed-eventmachine/features/support/env.rb
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 integrations/observed-eventmachine/lib/observed/eventmachine.rb
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Observed
module EM
VERSION = "0.2.0"
end
end

0 comments on commit 7c130d0

Please sign in to comment.