errbit_zmq_handler 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in errbit_zmq_handler.gemspec
4
+ gemspec
data/MIT-LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2011, Nick Recobra
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,42 @@
1
+ = Errbit 0MQ Handler
2
+
3
+ Errbit notifier extension for handling notices over 0mq socket.
4
+
5
+ One should use this library to listen to Hoptoad 0MQ Notifier powered app (https://github.com/oruen/hoptoad_zmq_notifier)
6
+
7
+ Advantage of using Errbit 0MQ Handler is async notices processing. You could fire notices from the client and not depend on
8
+ timeouts, service unavailability and services errors.
9
+
10
+ == Installation
11
+
12
+ Install zeromq 2.1 from http://www.zeromq.org or your favorite package system.
13
+
14
+ Get Errbit https://github.com/oruen/errbit (my fork is more stable and featured :)
15
+
16
+ Install the gem:
17
+
18
+ gem install errbit_zmq_handler
19
+
20
+ == Usage
21
+
22
+ Config 0MQ handler by defining it's address it <tt>config/initializers/errbit_zmq_handler.rb</tt>:
23
+
24
+ ErrbitZmqHandler.configure do |config|
25
+ # Address to bind to listen exception notifications
26
+ config.uri = "tcp://127.0.0.1:9998"
27
+ end
28
+
29
+ Starting handler daemon:
30
+ APP_ROOT=/path/to/app/root RAILS_ENV=production errbit_zmq_handler start
31
+
32
+ Stop handler daemon:
33
+ APP_ROOT=/path/to/app/root RAILS_ENV=production errbit_zmq_handler stop
34
+
35
+ Restart handler daemon:
36
+ APP_ROOT=/path/to/app/root RAILS_ENV=production errbit_zmq_handler restart
37
+
38
+
39
+ == License
40
+
41
+ HoptoadZmqNotifier is Copyright © 2011 oruen. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
42
+
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec) do |t|
6
+ end
7
+ task :default => :spec
8
+
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ app_root = ENV["APP_ROOT"] || "."
4
+
5
+ require 'daemon_spawn'
6
+
7
+ module ErrbitZmqHandler
8
+ class Daemon < DaemonSpawn::Base
9
+ def start(args)
10
+ puts "[#{Time.now}] Starting"
11
+ require File.expand_path('config/environment', working_dir)
12
+ Rails.logger = ActiveSupport::BufferedLogger.new log_file
13
+ Mongoid.logger = Rails.logger
14
+ ErrbitZmqHandler.handler.start!
15
+ end
16
+
17
+ def stop
18
+ puts "[#{Time.now}] Shutting down"
19
+ end
20
+ end
21
+ end
22
+
23
+ ErrbitZmqHandler::Daemon.spawn!(:log_file => "#{app_root}/log/errbit_zmq_handler.log",
24
+ :pid_file => "#{app_root}/tmp/pids/errbit_zmq_handler.pid",
25
+ :sync_log => true,
26
+ :singleton => true,
27
+ :working_dir => app_root)
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "errbit_zmq_handler/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "errbit_zmq_handler"
7
+ s.version = ErrbitZmqHandler::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Nick Recobra"]
10
+ s.email = ["oruenu@gmail.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{Errbit handler for 0MQ notices}
13
+ s.description = %q{Errbit extension providing handler for notices transfered via 0MQ}
14
+
15
+ s.rubyforge_project = "errbit_zmq_handler"
16
+
17
+ s.add_dependency "ffi", ">= 0"
18
+ s.add_dependency "yajl-ruby", "> 0"
19
+ s.add_dependency "dripdrop", ">= 0.10.0.beta2"
20
+ s.add_dependency "daemon-spawn", ">= 0.4.0"
21
+
22
+ s.add_development_dependency 'rspec', '>= 2.5.0'
23
+
24
+ s.files = `git ls-files`.split("\n")
25
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
26
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
27
+ s.require_paths = ["lib"]
28
+ end
@@ -0,0 +1,32 @@
1
+ # encoding: utf-8
2
+ module ErrbitZmqHandler
3
+ # Used to set up and modify settings for the notifier.
4
+ class Configuration
5
+
6
+ OPTIONS = [:uri].freeze
7
+
8
+ # The uri to bind to (0MQ socket)
9
+ attr_accessor :uri
10
+
11
+ # Allows config options to be read like a hash
12
+ #
13
+ # @param [Symbol] option Key for a given attribute
14
+ def [](option)
15
+ send(option)
16
+ end
17
+
18
+ # Returns a hash of all configurable options
19
+ def to_hash
20
+ OPTIONS.inject({}) do |hash, option|
21
+ hash.merge(option.to_sym => send(option))
22
+ end
23
+ end
24
+
25
+ # Returns a hash of all configurable options merged with +hash+
26
+ #
27
+ # @param [Hash] hash A set of configuration options that will take precedence over the defaults
28
+ def merge(hash)
29
+ to_hash.merge(hash)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+ require 'dripdrop'
3
+ module ErrbitZmqHandler
4
+ class Handler < DripDrop::Node
5
+ attr_accessor :uri
6
+ def action
7
+ self.uri = ErrbitZmqHandler.configuration.uri
8
+ route :exceptions, :zmq_subscribe, uri, :bind, :msg_format => :raw
9
+
10
+ exceptions.on_recv do |messages|
11
+ xml = messages.first.copy_out_string
12
+ puts "[#{Time.now}] got notice"
13
+ start = Time.now
14
+ Notice.from_xml(xml)
15
+ puts "Notice saved in #{Time.now - start} seconds\n\n"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module ErrbitZmqHandler
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,33 @@
1
+ # encoding: utf-8
2
+
3
+ Thread.abort_on_exception = true
4
+
5
+ module ErrbitZmqHandler
6
+ autoload :Configuration, 'errbit_zmq_handler/configuration'
7
+ autoload :Handler, 'errbit_zmq_handler/handler'
8
+ autoload :VERSION, 'errbit_zmq_handler/version'
9
+ class << self
10
+ # A Errbit ZMQ Handler configuration object. Must act like a hash and return sensible
11
+ # values for all Hoptoad ZMQ configuration options. See ErrbitZmqHandler::Configuration.
12
+ attr_accessor :configuration
13
+
14
+ # Call this method to modify defaults in your initializers.
15
+ #
16
+ # @example
17
+ # ErrbitZmqHandler.configure do |config|
18
+ # config.mailbox_size = 1000
19
+ # config.uri = 'tcp://errbit.home:9999'
20
+ # end
21
+ def configure
22
+ self.configuration ||= Configuration.new
23
+ yield(configuration)
24
+ end
25
+
26
+ # The handler object is responsible for delivering formatted data to the Hoptoad server.
27
+ # Must respond to #start!. See ErrbitZmqHandler::Handler.
28
+ def handler
29
+ @handler ||= Handler.new.tap {|h| h.uri = ErrbitZmqHandler.configuration.uri}
30
+ end
31
+ end
32
+ end
33
+
@@ -0,0 +1,30 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <notice version="2.0">
3
+ <api-key>76fdb93ab2cf276ec080671a8b3d3866</api-key>
4
+ <notifier>
5
+ <name>Hoptoad Notifier</name>
6
+ <version>1.2.4</version>
7
+ <url>http://hoptoadapp.com</url>
8
+ </notifier>
9
+ <error>
10
+ <class>RuntimeError</class>
11
+ <message>RuntimeError: I've made a huge mistake</message>
12
+ <backtrace>
13
+ <line method="public" file="/testapp/app/models/user.rb" number="53"/>
14
+ <line method="index" file="/testapp/app/controllers/users_controller.rb" number="14"/>
15
+ </backtrace>
16
+ </error>
17
+ <request>
18
+ <url>http://example.com</url>
19
+ <component/>
20
+ <action/>
21
+ <cgi-data>
22
+ <var key="SERVER_NAME">example.org</var>
23
+ <var key="HTTP_USER_AGENT">Mozilla</var>
24
+ </cgi-data>
25
+ </request>
26
+ <server-environment>
27
+ <project-root>/testapp</project-root>
28
+ <environment-name>production</environment-name>
29
+ </server-environment>
30
+ </notice>
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe ErrbitZmqHandler::Configuration do
5
+ it "should have an uri" do
6
+ assert_config_overridable :uri
7
+ end
8
+
9
+ it "should set handler uri" do
10
+ @uri = "tcp://localhost"
11
+ ErrbitZmqHandler.configure do |config|
12
+ config.uri = @uri
13
+ end
14
+
15
+ ErrbitZmqHandler.handler.uri.should == @uri
16
+ end
17
+ end
18
+
19
+ def assert_config_overridable(option, value = 'a value')
20
+ config = ErrbitZmqHandler::Configuration.new
21
+ config.send(:"#{option}=", value)
22
+ config.send(option).should == value
23
+ end
24
+
25
+ def assert_config_default(option, default_value, config = nil)
26
+ config ||= ErrbitZmqHandler::Configuration.new
27
+ config.send(option).should == default_value
28
+ end
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+ require 'rubygems'
3
+ require 'rspec'
4
+ require 'errbit_zmq_handler'
5
+
6
+ RSpec.configure do |c|
7
+ c.mock_with :rspec
8
+ end
9
+
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: errbit_zmq_handler
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Nick Recobra
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-03-03 00:00:00.000000000 +03:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: ffi
17
+ requirement: &2164843040 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *2164843040
26
+ - !ruby/object:Gem::Dependency
27
+ name: yajl-ruby
28
+ requirement: &2164842500 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>'
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *2164842500
37
+ - !ruby/object:Gem::Dependency
38
+ name: dripdrop
39
+ requirement: &2164842040 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: 0.10.0.beta2
45
+ type: :runtime
46
+ prerelease: false
47
+ version_requirements: *2164842040
48
+ - !ruby/object:Gem::Dependency
49
+ name: daemon-spawn
50
+ requirement: &2164841580 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: 0.4.0
56
+ type: :runtime
57
+ prerelease: false
58
+ version_requirements: *2164841580
59
+ - !ruby/object:Gem::Dependency
60
+ name: rspec
61
+ requirement: &2164841120 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: 2.5.0
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: *2164841120
70
+ description: Errbit extension providing handler for notices transfered via 0MQ
71
+ email:
72
+ - oruenu@gmail.com
73
+ executables:
74
+ - errbit_zmq_handler
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - .gitignore
79
+ - Gemfile
80
+ - MIT-LICENSE
81
+ - README.rdoc
82
+ - Rakefile
83
+ - bin/errbit_zmq_handler
84
+ - errbit_zmq_handler.gemspec
85
+ - lib/errbit_zmq_handler.rb
86
+ - lib/errbit_zmq_handler/configuration.rb
87
+ - lib/errbit_zmq_handler/handler.rb
88
+ - lib/errbit_zmq_handler/version.rb
89
+ - spec/fixtures/notice.xml
90
+ - spec/lib/errbit_zmq_handler/configuration_spec.rb
91
+ - spec/spec_helper.rb
92
+ has_rdoc: true
93
+ homepage: ''
94
+ licenses: []
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project: errbit_zmq_handler
113
+ rubygems_version: 1.5.2
114
+ signing_key:
115
+ specification_version: 3
116
+ summary: Errbit handler for 0MQ notices
117
+ test_files:
118
+ - spec/fixtures/notice.xml
119
+ - spec/lib/errbit_zmq_handler/configuration_spec.rb
120
+ - spec/spec_helper.rb