fluent-plugin-resque 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ /fluent/
2
+ /pkg/
3
+ /coverage/
4
+ /vendor/
5
+ Gemfile.lock
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ rvm:
2
+ - 1.9.2
3
+ - 1.9.3
4
+
5
+ script: bundle exec rake test
data/AUTHORS ADDED
@@ -0,0 +1 @@
1
+ Yuichi Tateno <hotchpotch _at_ gmail.com>
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source :rubygems
2
+
3
+ gemspec
4
+
5
+ gem "simplecov", :require => false
data/README.rdoc ADDED
@@ -0,0 +1,26 @@
1
+ = Fluent event to Resque queue plugin
2
+
3
+ = Installation
4
+
5
+ $ fluent-gem install fluent-plugin-resque
6
+
7
+ = Usage
8
+
9
+ <match queue.name>
10
+ type resque
11
+ redis hostname:port/namespace
12
+ queue file_serve
13
+ # Resque.enqueue_to('file_serve', 'Queue::Name', record)
14
+ </match>
15
+
16
+ <match queue.name.foo>
17
+ type resque
18
+ queue file_serve
19
+ remove_tag_prefix queue.
20
+ # Resque.enqueue_to('file_serve', 'Name::Foo', record)
21
+ </match>
22
+
23
+ = Copyright
24
+
25
+ Copyright:: Copyright (c) 2012- Yuichi Tateno
26
+ License:: Apache License, Version 2.0
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |test|
7
+ test.libs << 'lib' << 'test'
8
+ test.test_files = FileList['test/plugin/*.rb']
9
+ test.verbose = true
10
+ end
11
+
12
+ task :coverage do |t|
13
+ ENV['SIMPLE_COV'] = '1'
14
+ Rake::Task["test"].invoke
15
+ end
16
+
17
+ task :default => [:build]
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "fluent-plugin-resque"
6
+ gem.description = "Resque enqueue plugin"
7
+ gem.homepage = "https://github.com/hotchpotch/fluent-plugin-resque"
8
+ gem.summary = gem.description
9
+ gem.version = File.read("VERSION").strip
10
+ gem.authors = ["Yuichi Tateno"]
11
+ gem.email = "hotchpotch@gmail.com"
12
+ gem.has_rdoc = false
13
+ gem.files = `git ls-files`.split("\n")
14
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ gem.require_paths = ['lib']
17
+
18
+ gem.add_dependency "fluentd", ">= 0.10.8"
19
+ gem.add_dependency "resque", ">= 1.0.0"
20
+ gem.add_development_dependency "rake", ">= 0.9.2"
21
+ gem.add_development_dependency "simplecov", ">= 0.5.4"
22
+ gem.add_development_dependency "rr", ">= 1.0.0"
23
+ end
@@ -0,0 +1,63 @@
1
+
2
+ module Fluent
3
+ class ResqueOutput < BufferedOutput
4
+ Fluent::Plugin.register_output('resque', self)
5
+
6
+ include SetTagKeyMixin
7
+ config_set_default :include_tag_key, false
8
+
9
+ include SetTimeKeyMixin
10
+ config_set_default :include_time_key, true
11
+
12
+ config_param :queue, :string
13
+ config_param :redis, :string, :default => nil
14
+ config_param :remove_tag_prefix, :string, :default => nil
15
+
16
+ def initialize
17
+ super
18
+ require 'resque'
19
+ end
20
+
21
+ def configure(conf)
22
+ super
23
+
24
+ Resque.redis = conf['redis'] if conf['redis']
25
+
26
+ if remove_tag_prefix = conf['remove_tag_prefix']
27
+ @remove_tag_prefix = Regexp.new('^' + Regexp.escape(remove_tag_prefix))
28
+ end
29
+ end
30
+
31
+ def start
32
+ super
33
+ end
34
+
35
+ def shutdown
36
+ super
37
+ end
38
+
39
+ def format(tag, time, record)
40
+ [tag, time, record].to_msgpack
41
+ end
42
+
43
+ def write(chunk)
44
+ queue_name = @queue_mapped ? chunk.key : @queue
45
+
46
+ chunk.msgpack_each {|tag, time, record|
47
+ record[@time_key] = Time.at(time || record[@time_key]) if @include_time_key
48
+ tag = remove_prefix(tag) if @remove_tag_prefix
49
+ record[@tag_key] = tag if @include_tag_key
50
+ Resque.enqueue_to(queue_name, camelize(tag), record)
51
+ }
52
+ end
53
+
54
+ private
55
+ def remove_prefix(tag)
56
+ tag.to_s.sub(@remove_tag_prefix, '')
57
+ end
58
+
59
+ def camelize(name)
60
+ name.to_s.gsub(/\.(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,58 @@
1
+ require 'test_helper'
2
+ require 'resque'
3
+
4
+ class ResqueOutputTest < Test::Unit::TestCase
5
+ def setup
6
+ Fluent::Test.setup
7
+ require 'fluent/plugin/out_resque'
8
+ end
9
+
10
+ CONFIG = %[
11
+ type resque
12
+ queue test_queue
13
+ ]
14
+
15
+ def create_driver(conf = CONFIG)
16
+ Fluent::Test::BufferedOutputTestDriver.new(Fluent::ResqueOutput) {
17
+ }.configure(conf)
18
+ end
19
+
20
+ def test_write
21
+ d = create_driver
22
+ time = Time.at Time.now.to_i
23
+ d.emit({'a' => 1}, time)
24
+ d.emit({'b' => 2}, time)
25
+ mock(Resque).enqueue_to("test_queue", "Test", {"a" => 1 , "time" => time})
26
+ mock(Resque).enqueue_to("test_queue", "Test", {"b" => 2 , "time" => time})
27
+ d.run
28
+ end
29
+
30
+ def test_write_except_time_key
31
+ d = create_driver(CONFIG + "\ninclude_time_key false")
32
+ time = Time.at Time.now.to_i
33
+ d.emit({'a' => 1}, time)
34
+ mock(Resque).enqueue_to("test_queue", "Test", {"a" => 1})
35
+ d.run
36
+ end
37
+
38
+ def test_write_include_tag_key
39
+ d = create_driver(CONFIG + "\ninclude_tag_key true")
40
+ time = Time.at Time.now.to_i
41
+ d.emit({'a' => 1}, time)
42
+ mock(Resque).enqueue_to("test_queue", "Test", {"a" => 1, "time" => time, "tag" => 'test'})
43
+ d.run
44
+ end
45
+
46
+ def test_write_with_remove_tag_prefix
47
+ d = create_driver(CONFIG + "\nremove_tag_prefix te")
48
+ time = Time.at Time.now.to_i
49
+ d.emit({'a' => 1}, time)
50
+ mock(Resque).enqueue_to("test_queue", "St", {"a" => 1, "time" => time})
51
+ d.run
52
+ end
53
+
54
+ def test_change_redis_host
55
+ mock(Resque).redis = "localhost:11111/namespace"
56
+ d = create_driver(CONFIG + "\nredis localhost:11111/namespace")
57
+ end
58
+ end
@@ -0,0 +1,20 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ require 'rr'
5
+ require 'test/unit'
6
+ class Test::Unit::TestCase
7
+ include RR::Adapters::TestUnit
8
+ end
9
+
10
+ if ENV['SIMPLE_COV']
11
+ require 'simplecov'
12
+ SimpleCov.start do
13
+ add_filter 'test/'
14
+ add_filter 'pkg/'
15
+ add_filter 'vendor/'
16
+ end
17
+ end
18
+
19
+ require 'test/unit'
20
+ require 'fluent/test'
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-resque
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Yuichi Tateno
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: fluentd
16
+ requirement: &2158383160 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.10.8
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2158383160
25
+ - !ruby/object:Gem::Dependency
26
+ name: resque
27
+ requirement: &2158382640 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 1.0.0
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *2158382640
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
38
+ requirement: &2158382160 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: 0.9.2
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *2158382160
47
+ - !ruby/object:Gem::Dependency
48
+ name: simplecov
49
+ requirement: &2158381700 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.5.4
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *2158381700
58
+ - !ruby/object:Gem::Dependency
59
+ name: rr
60
+ requirement: &2158381240 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: 1.0.0
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *2158381240
69
+ description: Resque enqueue plugin
70
+ email: hotchpotch@gmail.com
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - .gitignore
76
+ - .travis.yml
77
+ - AUTHORS
78
+ - Gemfile
79
+ - README.rdoc
80
+ - Rakefile
81
+ - VERSION
82
+ - fluent-plugin-resque.gemspec
83
+ - lib/fluent/plugin/out_resque.rb
84
+ - test/plugin/out_resque.rb
85
+ - test/test_helper.rb
86
+ homepage: https://github.com/hotchpotch/fluent-plugin-resque
87
+ licenses: []
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 1.8.16
107
+ signing_key:
108
+ specification_version: 3
109
+ summary: Resque enqueue plugin
110
+ test_files:
111
+ - test/plugin/out_resque.rb
112
+ - test/test_helper.rb