jackal 0.2.4 → 0.3.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/jackal/callback.rb +14 -11
- data/lib/jackal/loader.rb +6 -2
- data/lib/jackal/utils.rb +14 -5
- data/lib/jackal/utils/config.rb +28 -3
- data/lib/jackal/utils/process.rb +22 -7
- data/lib/jackal/utils/spec/helpers.rb +1 -1
- data/lib/jackal/version.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 87d40ed9a2151a4e456b7a80a817e81856b471b5
         | 
| 4 | 
            +
              data.tar.gz: cfda4c42c5e359630c8d296c1f8be8f4fbb1956a
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: d3b2963e4f7f5ee5078665980843904fd17afd1edd04b1ff1865e6bbfa109826fb688f1a68645d0f11e8465c549337cd7450de81f578070ccd2e0477c021645b
         | 
| 7 | 
            +
              data.tar.gz: d2dc8f35b125bdf42beb18a30786d9396adcf5e67d1b17e7a059fa50a19310c8353c51555f1c30c639e7b6455e4b3f188262ff2f3b0dd27812683b55045ebb2d
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -1,3 +1,9 @@ | |
| 1 | 
            +
            # v0.3.0
         | 
| 2 | 
            +
            * Force source looping on `Callback#completed`
         | 
| 3 | 
            +
            * Move HTTP hook configuration within jackal namespace
         | 
| 4 | 
            +
            * Add support for using `spawn` on a per-process basis
         | 
| 5 | 
            +
            * Link owner callback into formatters
         | 
| 6 | 
            +
             | 
| 1 7 | 
             
            # v0.2.4
         | 
| 2 8 | 
             
            * Fix nesting for orphan callback setup
         | 
| 3 9 | 
             
            * Add constant and memoization helpers into `Callback`
         | 
    
        data/lib/jackal/callback.rb
    CHANGED
    
    | @@ -1,4 +1,5 @@ | |
| 1 1 | 
             
            require 'jackal'
         | 
| 2 | 
            +
            require 'pp'
         | 
| 2 3 |  | 
| 3 4 | 
             
            module Jackal
         | 
| 4 5 | 
             
              # Jackal customized callback
         | 
| @@ -22,7 +23,7 @@ module Jackal | |
| 22 23 | 
             
                  super
         | 
| 23 24 | 
             
                  if(service_config[:formatters])
         | 
| 24 25 | 
             
                    @formatters = service_config[:formatters].map do |klass_name|
         | 
| 25 | 
            -
                      constantize(klass_name).new
         | 
| 26 | 
            +
                      constantize(klass_name).new(self)
         | 
| 26 27 | 
             
                    end
         | 
| 27 28 | 
             
                  end
         | 
| 28 29 | 
             
                end
         | 
| @@ -40,7 +41,7 @@ module Jackal | |
| 40 41 | 
             
                # @return [Utils::Process]
         | 
| 41 42 | 
             
                def process_manager
         | 
| 42 43 | 
             
                  memoize(:process_manager) do
         | 
| 43 | 
            -
                    Utils::Process.new
         | 
| 44 | 
            +
                    Utils::Process.new(app_config.fetch(:process_manager, Smash.new))
         | 
| 44 45 | 
             
                  end
         | 
| 45 46 | 
             
                end
         | 
| 46 47 |  | 
| @@ -77,13 +78,13 @@ module Jackal | |
| 77 78 | 
             
                def failed(payload, message, reason='No reason provided')
         | 
| 78 79 | 
             
                  error "Processing of #{message} failed! Reason: #{reason}"
         | 
| 79 80 | 
             
                  message.confirm!
         | 
| 80 | 
            -
                   | 
| 81 | 
            -
                  source = Carnivore::Supervisor.supervisor[ | 
| 81 | 
            +
                  dest = destination(:error, payload)
         | 
| 82 | 
            +
                  source = Carnivore::Supervisor.supervisor[dest]
         | 
| 82 83 | 
             
                  if(source)
         | 
| 83 84 | 
             
                    error "Sending #{message} to error handler: #{source}"
         | 
| 84 85 | 
             
                    source.transmit(payload)
         | 
| 85 86 | 
             
                  else
         | 
| 86 | 
            -
                    error "No error source found for generated source path: #{ | 
| 87 | 
            +
                    error "No error source found for generated source path: #{dest}"
         | 
| 87 88 | 
             
                    info "Processing of message #{message} has completed. Message now discarded."
         | 
| 88 89 | 
             
                  end
         | 
| 89 90 | 
             
                end
         | 
| @@ -95,21 +96,23 @@ module Jackal | |
| 95 96 | 
             
                def completed(payload, message)
         | 
| 96 97 | 
             
                  message.confirm!
         | 
| 97 98 | 
             
                  info "Processing of #{message} complete on this callback"
         | 
| 98 | 
            -
                  forward(payload)
         | 
| 99 | 
            +
                  forward(payload, source.name)
         | 
| 99 100 | 
             
                end
         | 
| 100 101 |  | 
| 101 102 | 
             
                # Forward payload to output source
         | 
| 102 103 | 
             
                #
         | 
| 103 104 | 
             
                # @param payload [Hash]
         | 
| 104 | 
            -
                def forward(payload)
         | 
| 105 | 
            -
                   | 
| 106 | 
            -
             | 
| 105 | 
            +
                def forward(payload, dest=nil)
         | 
| 106 | 
            +
                  unless(dest)
         | 
| 107 | 
            +
                    dest = destination(:output, payload)
         | 
| 108 | 
            +
                  end
         | 
| 109 | 
            +
                  source = Carnivore::Supervisor.supervisor[dest]
         | 
| 107 110 | 
             
                  if(source)
         | 
| 108 111 | 
             
                    info "Forwarding payload to output destination... (#{source})"
         | 
| 109 | 
            -
                    debug "Forwarded payload: #{payload. | 
| 112 | 
            +
                    debug "Forwarded payload: #{payload.pretty_inspect}"
         | 
| 110 113 | 
             
                    source.transmit(payload)
         | 
| 111 114 | 
             
                  else
         | 
| 112 | 
            -
                    warn "No destination source found for generated source path: #{ | 
| 115 | 
            +
                    warn "No destination source found for generated source path: #{dest}"
         | 
| 113 116 | 
             
                    info "Processing of message has completed. Message now discarded."
         | 
| 114 117 | 
             
                  end
         | 
| 115 118 | 
             
                end
         | 
    
        data/lib/jackal/loader.rb
    CHANGED
    
    | @@ -10,8 +10,12 @@ module Jackal | |
| 10 10 | 
             
                  # @param opts [Hash]
         | 
| 11 11 | 
             
                  def run!(opts)
         | 
| 12 12 |  | 
| 13 | 
            -
                    if(ENV['JACKAL_TESTING_MODE'] | 
| 14 | 
            -
                       | 
| 13 | 
            +
                    if(ENV['JACKAL_TESTING_MODE'])
         | 
| 14 | 
            +
                      if(!opts[:config])
         | 
| 15 | 
            +
                        Carnivore.configure!(:verify)
         | 
| 16 | 
            +
                      else
         | 
| 17 | 
            +
                        Carnivore.configure!(opts[:config], :force)
         | 
| 18 | 
            +
                      end
         | 
| 15 19 | 
             
                    else
         | 
| 16 20 | 
             
                      Carnivore.configure!(opts[:config])
         | 
| 17 21 | 
             
                      Carnivore::Config.immutable!
         | 
    
        data/lib/jackal/utils.rb
    CHANGED
    
    | @@ -4,6 +4,12 @@ module Jackal | |
| 4 4 | 
             
              # Helper utilities
         | 
| 5 5 | 
             
              module Utils
         | 
| 6 6 |  | 
| 7 | 
            +
                # Valid configuration paths for hook configuration
         | 
| 8 | 
            +
                HTTP_HOOK_CONFIG = [
         | 
| 9 | 
            +
                  [:http_hook],
         | 
| 10 | 
            +
                  [:jackal, :http_hook]
         | 
| 11 | 
            +
                ]
         | 
| 12 | 
            +
             | 
| 7 13 | 
             
                autoload :Spec, 'jackal/utils/spec'
         | 
| 8 14 | 
             
                autoload :Payload, 'jackal/utils/payload'
         | 
| 9 15 | 
             
                autoload :Config, 'jackal/utils/config'
         | 
| @@ -16,18 +22,21 @@ module Jackal | |
| 16 22 |  | 
| 17 23 | 
             
                class << self
         | 
| 18 24 |  | 
| 19 | 
            -
                  # Load  | 
| 25 | 
            +
                  # Load the HTTP Hook if configured
         | 
| 20 26 | 
             
                  #
         | 
| 21 27 | 
             
                  # @return [TrueClass, FalseClass]
         | 
| 22 28 | 
             
                  def load_http_hook
         | 
| 23 | 
            -
                     | 
| 29 | 
            +
                    hook_config = HTTP_HOOK_CONFIG.map do |path|
         | 
| 30 | 
            +
                      Carnivore::Config.get(*path)
         | 
| 31 | 
            +
                    end.compact.first
         | 
| 32 | 
            +
                    if(hook_config)
         | 
| 24 33 | 
             
                      Carnivore.configure do
         | 
| 25 34 | 
             
                        Carnivore::Source.build(
         | 
| 26 35 | 
             
                          :type => :http_endpoints,
         | 
| 27 36 | 
             
                          :args => {
         | 
| 28 | 
            -
                            :name => : | 
| 29 | 
            -
                            :bind =>  | 
| 30 | 
            -
                            :port =>  | 
| 37 | 
            +
                            :name => :jackal_http_hook,
         | 
| 38 | 
            +
                            :bind => hook_config.fetch(:bind, "0.0.0.0"),
         | 
| 39 | 
            +
                            :port => hook_config.fetch(:port, 8989)
         | 
| 31 40 | 
             
                          }
         | 
| 32 41 | 
             
                        )
         | 
| 33 42 | 
             
                      end
         | 
    
        data/lib/jackal/utils/config.rb
    CHANGED
    
    | @@ -4,6 +4,20 @@ module Jackal | |
| 4 4 | 
             
              module Utils
         | 
| 5 5 | 
             
                module Config
         | 
| 6 6 |  | 
| 7 | 
            +
                  # Load extra modules automatically
         | 
| 8 | 
            +
                  def self.included(klass)
         | 
| 9 | 
            +
                    klass.class_eval do
         | 
| 10 | 
            +
                      include Bogo::AnimalStrings
         | 
| 11 | 
            +
                    end
         | 
| 12 | 
            +
                  end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                  # Load extra modules automatically
         | 
| 15 | 
            +
                  def self.extended(klass)
         | 
| 16 | 
            +
                    klass.class_eval do
         | 
| 17 | 
            +
                      extend Bogo::AnimalStrings
         | 
| 18 | 
            +
                    end
         | 
| 19 | 
            +
                  end
         | 
| 20 | 
            +
             | 
| 7 21 | 
             
                  # @return [Symbol] name of service
         | 
| 8 22 | 
             
                  def service_name(class_name = self.class.name)
         | 
| 9 23 | 
             
                    config_path(class_name).last.to_sym
         | 
| @@ -12,7 +26,7 @@ module Jackal | |
| 12 26 | 
             
                  # @return [Array] key path in configuration
         | 
| 13 27 | 
             
                  def config_path(class_name = self.class.name)
         | 
| 14 28 | 
             
                    class_name.split('::')[0,2].map do |string|
         | 
| 15 | 
            -
                      string | 
| 29 | 
            +
                      snake(string)
         | 
| 16 30 | 
             
                    end
         | 
| 17 31 | 
             
                  end
         | 
| 18 32 |  | 
| @@ -21,6 +35,16 @@ module Jackal | |
| 21 35 | 
             
                    config_path.join('_')
         | 
| 22 36 | 
             
                  end
         | 
| 23 37 |  | 
| 38 | 
            +
                  # @return [Smash] application configuration
         | 
| 39 | 
            +
                  def app_config
         | 
| 40 | 
            +
                    Carnivore::Config.fetch(
         | 
| 41 | 
            +
                      snake(
         | 
| 42 | 
            +
                        self.class.name.split('::').first
         | 
| 43 | 
            +
                      ),
         | 
| 44 | 
            +
                      Smash.new
         | 
| 45 | 
            +
                    )
         | 
| 46 | 
            +
                  end
         | 
| 47 | 
            +
             | 
| 24 48 | 
             
                  # @return [Smash] service configuration
         | 
| 25 49 | 
             
                  def service_config
         | 
| 26 50 | 
             
                    Carnivore::Config.get(*config_path) || Smash.new
         | 
| @@ -31,11 +55,12 @@ module Jackal | |
| 31 55 | 
             
                    service_config[:config] || Smash.new
         | 
| 32 56 | 
             
                  end
         | 
| 33 57 |  | 
| 34 | 
            -
                  #  | 
| 58 | 
            +
                  # Generate destination key based on direction
         | 
| 35 59 | 
             
                  #
         | 
| 36 60 | 
             
                  # @param direction [Symbol, String]
         | 
| 61 | 
            +
                  # @param payload [Smash]
         | 
| 37 62 | 
             
                  # @return [Symbol]
         | 
| 38 | 
            -
                  def destination(direction  | 
| 63 | 
            +
                  def destination(direction, payload)
         | 
| 39 64 | 
             
                    [source_prefix, direction].map(&:to_s).join('_').to_sym
         | 
| 40 65 | 
             
                  end
         | 
| 41 66 |  | 
    
        data/lib/jackal/utils/process.rb
    CHANGED
    
    | @@ -8,15 +8,24 @@ module Jackal | |
| 8 8 | 
             
              module Utils
         | 
| 9 9 | 
             
                class Process
         | 
| 10 10 |  | 
| 11 | 
            +
                  # Default path for IO tmp files
         | 
| 12 | 
            +
                  DEFAULT_STORAGE_DIRECTORY = '/tmp/jackal-process-manager'
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                  # @return [Smash] manager configuration
         | 
| 15 | 
            +
                  attr_reader :configuration
         | 
| 16 | 
            +
                  # @return [String] storage directory path
         | 
| 17 | 
            +
                  attr_reader :storage_directory
         | 
| 18 | 
            +
             | 
| 11 19 | 
             
                  # Create new instance
         | 
| 12 20 | 
             
                  #
         | 
| 21 | 
            +
                  # @param config [Smash] process manager configuration
         | 
| 13 22 | 
             
                  # @return [self]
         | 
| 14 | 
            -
                  def initialize
         | 
| 15 | 
            -
                    @ | 
| 16 | 
            -
             | 
| 17 | 
            -
                       | 
| 23 | 
            +
                  def initialize(config={})
         | 
| 24 | 
            +
                    @configuration = config.to_smash
         | 
| 25 | 
            +
                    @storage_directory = configuration.fetch(
         | 
| 26 | 
            +
                      :storage_directory, DEFAULT_STORAGE_DIRECTORY
         | 
| 18 27 | 
             
                    )
         | 
| 19 | 
            -
                    FileUtils.mkdir_p( | 
| 28 | 
            +
                    FileUtils.mkdir_p(storage_directory)
         | 
| 20 29 | 
             
                  end
         | 
| 21 30 |  | 
| 22 31 | 
             
                  # Create new process
         | 
| @@ -30,7 +39,13 @@ module Jackal | |
| 30 39 | 
             
                      command = Shellwords.shellsplit(command.first)
         | 
| 31 40 | 
             
                    end
         | 
| 32 41 | 
             
                    if(block_given?)
         | 
| 33 | 
            -
                       | 
| 42 | 
            +
                      if(configuration[:spawn])
         | 
| 43 | 
            +
                        yield ChildProcess::Unix::PosixSpawnProcess.new(command)
         | 
| 44 | 
            +
                      else
         | 
| 45 | 
            +
                        yield ChildProcess.build(*command)
         | 
| 46 | 
            +
                      end
         | 
| 47 | 
            +
                    else
         | 
| 48 | 
            +
                      raise ArgumentError.new('Expecting block but no block provided!')
         | 
| 34 49 | 
             
                    end
         | 
| 35 50 | 
             
                    true
         | 
| 36 51 | 
             
                  end
         | 
| @@ -40,7 +55,7 @@ module Jackal | |
| 40 55 | 
             
                  # @param args [String] argument list joined for filename
         | 
| 41 56 | 
             
                  # @return [IO]
         | 
| 42 57 | 
             
                  def create_io_tmp(*args)
         | 
| 43 | 
            -
                    path = File.join( | 
| 58 | 
            +
                    path = File.join(storage_directory, args.join('-'))
         | 
| 44 59 | 
             
                    FileUtils.mkdir_p(File.dirname(path))
         | 
| 45 60 | 
             
                    t_file = File.open(path, 'w+')
         | 
| 46 61 | 
             
                    t_file.sync
         | 
| @@ -40,7 +40,7 @@ def payload_for(style, args={}) | |
| 40 40 | 
             
                  if(args[:nest])
         | 
| 41 41 | 
             
                    Jackal::Utils.new_payload(:test, args[:nest] => MultiJson.load(File.read(path)))
         | 
| 42 42 | 
             
                  else
         | 
| 43 | 
            -
                    Jackal::Utils.new_payload(:test, File.read(path))
         | 
| 43 | 
            +
                    Jackal::Utils.new_payload(:test, MultiJson.load(File.read(path)))
         | 
| 44 44 | 
             
                  end
         | 
| 45 45 | 
             
                end
         | 
| 46 46 | 
             
              else
         | 
    
        data/lib/jackal/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: jackal
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.3.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Chris Roberts
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2015- | 
| 11 | 
            +
            date: 2015-02-26 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: carnivore
         |