jackal 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/CHANGELOG.md ADDED
@@ -0,0 +1,2 @@
1
+ # v0.1.0
2
+ * Initial commit
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,25 @@
1
+ # Contributing
2
+
3
+ ## Branches
4
+
5
+ ### `master` branch
6
+
7
+ The master branch is the current stable released version.
8
+
9
+ ### `develop` branch
10
+
11
+ The develop branch is the current edge of development.
12
+
13
+ ## Pull requests
14
+
15
+ * https://github.com/carnivore-rb/jackal/pulls
16
+
17
+ Please base all pull requests of the `develop` branch. Merges to
18
+ `master` only occur through the `develop` branch. Pull requests
19
+ based on `master` will likely be cherry picked.
20
+
21
+ ## Issues
22
+
23
+ Need to report an issue? Use the github issues:
24
+
25
+ * https://github.com/carnivore-rb/jackal/issues
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2014 Chris Roberts
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Jackal
2
+
3
+ Run your carnivores
data/bin/jackal ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'jackal'
3
+ require 'jackal/loader'
data/jackal.gemspec ADDED
@@ -0,0 +1,17 @@
1
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__)) + '/lib/'
2
+ require 'jackal/version'
3
+ Gem::Specification.new do |s|
4
+ s.name = 'jackal'
5
+ s.version = Jackal::VERSION.version
6
+ s.summary = 'Message processing helper'
7
+ s.author = 'Chris Roberts'
8
+ s.email = 'code@chrisroberts.org'
9
+ s.homepage = 'https://github.com/carnivore-rb/jackal'
10
+ s.description = 'Message processing helper'
11
+ s.require_path = 'lib'
12
+ s.license = 'Apache 2.0'
13
+ s.add_dependency 'carnivore'
14
+ s.add_dependency 'mixlib-cli'
15
+ s.files = Dir['lib/**/*'] + %w(jackal.gemspec README.md CHANGELOG.md CONTRIBUTING.md LICENSE)
16
+ s.executables << 'jackal'
17
+ end
data/lib/jackal.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'carnivore'
2
+
3
+ module Jackal
4
+ autoload :Cli, 'jackal/cli'
5
+ autoload :Callback, 'jackal/callback'
6
+ autoload :Error, 'jackal/error'
7
+ end
8
+
9
+ require 'jackal/version'
@@ -0,0 +1,61 @@
1
+ require 'jackal'
2
+
3
+ module Jackal
4
+ class Callback < Carnivore::Callback
5
+
6
+ def config_key
7
+ self.class.name.split('::').first.gsub(/(?<![A-Z])([A-Z])/, '_\1').sub(/^_/, '').downcase
8
+ end
9
+
10
+ def new_payload(payload)
11
+ Smash.new(
12
+ :id => Celluloid.uuid,
13
+ :data => payload
14
+ )
15
+ end
16
+
17
+ # message:: Original message
18
+ # Executes block and catches unexpected exceptions if encountered
19
+ def failure_wrap(message)
20
+ abort 'Failure wrap requires block for execution' unless block_given?
21
+ begin
22
+ payload = message[:message]
23
+ yield payload
24
+ rescue => e
25
+ error "!!! Unexpected failure encountered -> #{e.class}: #{e}"
26
+ debug "#{e.class}: #{e}\n#{(e.backtrace || []).join("\n")}"
27
+ failed(payload, message, e.message)
28
+ end
29
+ end
30
+
31
+ def failed(payload, message, reason='No reason provided')
32
+ error "Processing of #{message} failed! Reason: #{reason}"
33
+ message.confirm!
34
+ destination = "#{config_key}_error"
35
+ source = Carnivore::Supervisor.supervisor[destination]
36
+ error "Sending #{message} to error handler: #{source}"
37
+ source.transmit(payload)
38
+ end
39
+
40
+ def completed(payload, message)
41
+ message.confirm!
42
+ info "Processing of #{message} complete on this callback"
43
+ forward(payload)
44
+ end
45
+
46
+ def forward(payload)
47
+ destination = "#{config_key}_output"
48
+ source = Carnivore::Supervisor.supervisor[destination]
49
+ info "Forwarding payload to output destination... (#{source})"
50
+ debug "Forwarded payload: #{payload.inspect}"
51
+ source.transmit(payload)
52
+ end
53
+
54
+ def job_completed(name, payload, message)
55
+ info "Processing of message #{message} has completed within this component #{name}"
56
+ message.confirm!
57
+ forward(payload)
58
+ end
59
+
60
+ end
61
+ end
data/lib/jackal/cli.rb ADDED
@@ -0,0 +1,15 @@
1
+ require 'mixlib/cli'
2
+
3
+ module Jackal
4
+ class Cli
5
+ include Mixlib::CLI
6
+
7
+ option(:config_path,
8
+ :short => '-c FILE',
9
+ :long => '--config FILE',
10
+ :required => true,
11
+ :description => 'Path to configuration file'
12
+ )
13
+
14
+ end
15
+ end
@@ -0,0 +1,6 @@
1
+ require 'jackal'
2
+
3
+ module Jackal
4
+ class Error < StandardError
5
+ end
6
+ end
@@ -0,0 +1,47 @@
1
+ require 'carnivore'
2
+ require 'jackal'
3
+
4
+ cli = Jackal::Cli.new
5
+ cli.parse_options
6
+ Carnivore::Config.configure(cli.config)
7
+ Carnivore::Config.auto_symbolize(true)
8
+
9
+ (Carnivore::Config.get(:jackal, :require) || []).each do |path|
10
+ require path
11
+ end
12
+
13
+ begin
14
+ Carnivore::Utils.symbolize_hash(Carnivore::Config.hash_dup).each do |key, opts|
15
+ next if key == :jackal || !opts.is_a?(Hash)
16
+ Carnivore::Utils.info "Processing: #{opts.inspect}"
17
+ Carnivore.configure do
18
+ opts.fetch(:sources, {}).each do |kind, source_args|
19
+ source = Carnivore::Source.build(
20
+ :type => source_args[:type].to_sym,
21
+ :args => source_args.fetch(:args, {}).merge(:name => "#{key}_#{kind}")
22
+ )
23
+ Carnivore::Utils.info "Initialized new source: #{key}_#{kind}"
24
+ if(kind == :input)
25
+ opts.fetch(:callbacks, []).each do |klass_name|
26
+ klass = klass_name.split('::').inject(
27
+ Object.const_get(
28
+ key.to_s.split('_').map(&:capitalize).join
29
+ )
30
+ ) do |memo, name|
31
+ memo.const_get(name)
32
+ end
33
+ source.add_callback(klass_name, klass)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ Carnivore.start!
41
+ rescue => e
42
+ $stderr.puts "Unexpected failure encountered: #{e.class}: #{e}"
43
+ if(ENV['DEBUG'])
44
+ $stderr.puts "#{e.class}: #{e}\n#{e.backtrace.join("\n")}"
45
+ end
46
+ exit -1
47
+ end
@@ -0,0 +1,5 @@
1
+ module Jackal
2
+ class Version < Gem::Version
3
+ end
4
+ VERSION = Version.new('0.1.0')
5
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jackal
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Chris Roberts
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-05-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: carnivore
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
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: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: mixlib-cli
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Message processing helper
47
+ email: code@chrisroberts.org
48
+ executables:
49
+ - jackal
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - lib/jackal/callback.rb
54
+ - lib/jackal/version.rb
55
+ - lib/jackal/cli.rb
56
+ - lib/jackal/loader.rb
57
+ - lib/jackal/error.rb
58
+ - lib/jackal.rb
59
+ - jackal.gemspec
60
+ - README.md
61
+ - CHANGELOG.md
62
+ - CONTRIBUTING.md
63
+ - LICENSE
64
+ - bin/jackal
65
+ homepage: https://github.com/carnivore-rb/jackal
66
+ licenses:
67
+ - Apache 2.0
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 1.8.24
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: Message processing helper
90
+ test_files: []
91
+ has_rdoc: