mosaic-poller 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/Gemfile +14 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +37 -0
- data/lib/mosaic-poller.rb +1 -0
- data/lib/mosaic/poller.rb +78 -0
- data/lib/mosaic/poller/version.rb +5 -0
- data/lib/tasks/mosaic-poller_tasks.rake +4 -0
- data/mosaic-poller.gemspec +24 -0
- metadata +72 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
# Declare your gem's dependencies in mosaic-poller.gemspec.
|
4
|
+
# Bundler will treat runtime dependencies like base dependencies, and
|
5
|
+
# development dependencies will be added by default to the :development group.
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
# Declare any dependencies that are still in development here instead of in
|
9
|
+
# your gemspec. These might include edge Rails or gems from your path or
|
10
|
+
# Git. Remember to move these dependencies to your gemspec before releasing
|
11
|
+
# your gem to rubygems.org.
|
12
|
+
|
13
|
+
# To use debugger
|
14
|
+
# gem 'ruby-debug'
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2012 Mosaic Sales Solutions
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'Mosaic::Poller'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
Bundler::GemHelper.install_tasks
|
26
|
+
|
27
|
+
require 'rake/testtask'
|
28
|
+
|
29
|
+
Rake::TestTask.new(:test) do |t|
|
30
|
+
t.libs << 'lib'
|
31
|
+
t.libs << 'test'
|
32
|
+
t.pattern = 'test/**/*_test.rb'
|
33
|
+
t.verbose = false
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
task :default => :test
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'mosaic/poller'
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require 'daemons'
|
3
|
+
|
4
|
+
module Mosaic
|
5
|
+
class Poller
|
6
|
+
include Singleton
|
7
|
+
|
8
|
+
def initialize(name, options = {})
|
9
|
+
@name = name
|
10
|
+
@stopped = false
|
11
|
+
@poll_interval = options[:poll_interval] || 15
|
12
|
+
end
|
13
|
+
|
14
|
+
def run
|
15
|
+
Daemons.run_proc(@name, :dir => File.expand_path('tmp/pids'), :dir_mode => :normal, :backtrace => true) do
|
16
|
+
reload
|
17
|
+
process
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
protected
|
22
|
+
def debug(text)
|
23
|
+
logger.debug(@name) { text }
|
24
|
+
end
|
25
|
+
|
26
|
+
def error(text)
|
27
|
+
logger.error(@name) { text }
|
28
|
+
end
|
29
|
+
|
30
|
+
def info(text)
|
31
|
+
logger.info(@name) { text }
|
32
|
+
end
|
33
|
+
|
34
|
+
def logger
|
35
|
+
@logger ||= if defined?(Rails)
|
36
|
+
Rails.logger
|
37
|
+
else
|
38
|
+
require 'logger'
|
39
|
+
Logger.new(STDOUT)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def poll
|
44
|
+
raise NotImplementedException
|
45
|
+
end
|
46
|
+
|
47
|
+
def process
|
48
|
+
setup
|
49
|
+
info "START"
|
50
|
+
until @stopped
|
51
|
+
poll
|
52
|
+
sleep @poll_interval
|
53
|
+
end
|
54
|
+
info "STOP"
|
55
|
+
end
|
56
|
+
|
57
|
+
def reload
|
58
|
+
end
|
59
|
+
|
60
|
+
def setup
|
61
|
+
Signal.trap("HUP") do
|
62
|
+
reload
|
63
|
+
end
|
64
|
+
|
65
|
+
Signal.trap("INT") do
|
66
|
+
stop
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def stop
|
71
|
+
@stopped = true
|
72
|
+
end
|
73
|
+
|
74
|
+
def warn(text)
|
75
|
+
logger.warn(@name) { text }
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
# Maintain your gem's version:
|
6
|
+
require "mosaic/poller/version"
|
7
|
+
|
8
|
+
# Describe your gem and declare its dependencies:
|
9
|
+
Gem::Specification.new do |s|
|
10
|
+
s.name = "mosaic-poller"
|
11
|
+
s.version = Mosaic::Poller::VERSION
|
12
|
+
s.date = Date.today.to_s
|
13
|
+
|
14
|
+
s.authors = ["S. Brent Faulkner"]
|
15
|
+
s.email = ["brent.faulkner@mosaic.com"]
|
16
|
+
s.homepage = "http://github.com/mosaicxm/mosaic-poller"
|
17
|
+
s.summary = "Mosaic Sales Solutions basic polling daemon."
|
18
|
+
s.description = "Provides core support for implementing a daemon with a polling loop - including support for logging, reloading on hangup signal, etc."
|
19
|
+
|
20
|
+
s.files = `git ls-files`.split($/)
|
21
|
+
s.test_files = Dir["test/**/*"]
|
22
|
+
|
23
|
+
s.add_dependency "daemons", "~> 1.1"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mosaic-poller
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- S. Brent Faulkner
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: daemons
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.1'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.1'
|
30
|
+
description: Provides core support for implementing a daemon with a polling loop -
|
31
|
+
including support for logging, reloading on hangup signal, etc.
|
32
|
+
email:
|
33
|
+
- brent.faulkner@mosaic.com
|
34
|
+
executables: []
|
35
|
+
extensions: []
|
36
|
+
extra_rdoc_files: []
|
37
|
+
files:
|
38
|
+
- .gitignore
|
39
|
+
- Gemfile
|
40
|
+
- MIT-LICENSE
|
41
|
+
- README.rdoc
|
42
|
+
- Rakefile
|
43
|
+
- lib/mosaic-poller.rb
|
44
|
+
- lib/mosaic/poller.rb
|
45
|
+
- lib/mosaic/poller/version.rb
|
46
|
+
- lib/tasks/mosaic-poller_tasks.rake
|
47
|
+
- mosaic-poller.gemspec
|
48
|
+
homepage: http://github.com/mosaicxm/mosaic-poller
|
49
|
+
licenses: []
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
requirements: []
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 1.8.23
|
69
|
+
signing_key:
|
70
|
+
specification_version: 3
|
71
|
+
summary: Mosaic Sales Solutions basic polling daemon.
|
72
|
+
test_files: []
|