Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

System timer warning #22

Closed
wants to merge 4 commits into from

2 participants

@netshade
Owner

Warn users about system_timer when not installed, fallback to timeout

lib/instrumental/agent.rb
@@ -4,9 +4,25 @@
require 'thread'
require 'socket'
if RUBY_VERSION < "1.9"
- require 'system_timer'
+ begin
+ gem 'system_timer'
+ require 'system_timer'
+ InstrumentalTimeout = SystemTimer
+ rescue Exception => e
+ puts <<-EOMSG
+WARNING:: You do not currently have system_timer installed.
+It is strongly advised that you install this gem when using
+instrumental_agent. You can install it in your Gemfile via:
@jqr Owner
jqr added a note

How about "when using instrumental_agent with Ruby 1.8.x"

Also, only warn on that condition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@jqr
Owner

Otherwise :+1:

@netshade netshade closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 24, 2012
  1. remove system_timer extension installer

    Chris authored
  2. loudly warn users of Ruby 1.8 that they should install system_timer, …

    Chris authored
    …fall back to timeout
Commits on Mar 6, 2012
  1. clarify warning

    Chris authored
  2. avoid warning for jruby 1.8 users

    Chris authored
This page is out of date. Refresh to see the latest.
View
20 ext/mkrf_conf.rb
@@ -1,20 +0,0 @@
-require 'rubygems'
-require 'rubygems/command.rb'
-require 'rubygems/dependency_installer.rb'
-begin
- Gem::Command.build_args = ARGV
- rescue NoMethodError
-end
-inst = Gem::DependencyInstaller.new
-begin
- if RUBY_VERSION < "1.9"
- inst.install "system_timer", "~> 1.2"
- end
-rescue
- puts "Couldn't install system_timer gem, required on Ruby < 1.9"
- exit(1)
-end
-
-f = File.open(File.join(File.dirname(__FILE__), "Rakefile"), "w") # create dummy rakefile to indicate success
-f.write("task :default\n")
-f.close
View
1  instrumental_agent.gemspec
@@ -14,7 +14,6 @@ Gem::Specification.new do |s|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
- s.extensions = 'ext/mkrf_conf.rb'
s.add_development_dependency(%q<rake>, [">= 0"])
s.add_development_dependency(%q<rspec>, ["~> 2.0"])
s.add_development_dependency(%q<fuubar>, [">= 0"])
View
24 lib/instrumental/agent.rb
@@ -3,10 +3,27 @@
require 'logger'
require 'thread'
require 'socket'
-if RUBY_VERSION < "1.9"
- require 'system_timer'
+if RUBY_VERSION < "1.9" && RUBY_PLATFORM != "java"
+ begin
+ gem 'system_timer'
+ require 'system_timer'
+ InstrumentalTimeout = SystemTimer
+ rescue Exception => e
+ puts <<-EOMSG
+WARNING:: You do not currently have system_timer installed.
+It is strongly advised that you install this gem when using
+instrumental_agent with Ruby 1.8.x. You can install it in
+your Gemfile via:
+gem 'system_timer'
+or manually via:
+gem install system_timer
+ EOMSG
+ require 'timeout'
+ InstrumentalTimeout = Timeout
+ end
else
require 'timeout'
+ InstrumentalTimeout = Timeout
end
@@ -190,8 +207,7 @@ def logger
private
def with_timeout(time, &block)
- tmr_klass = RUBY_VERSION < "1.9" ? SystemTimer : Timeout
- tmr_klass.timeout(time) { yield }
+ InstrumentalTimeout.timeout(time) { yield }
end
def valid_note?(note)
Something went wrong with that request. Please try again.