Sha256: 2a97accf74741bc45c244f598e5899a91f20c1866e0fbbda171480d0aa30107b

Contents?: true

Size: 1.55 KB

Versions: 3

Compression:

Stored size: 1.55 KB

Contents

require 'logger'
require 'fileutils'
require 'thread'
require_relative 'background/base'
require_relative 'processing/base'

module Entangler
  module Executor
    class Base
      include Entangler::Executor::Background::Base, Entangler::Executor::Processing::Base

      attr_reader :base_dir

      def initialize(base_dir, opts = {})
        @base_dir = File.realpath(File.expand_path(base_dir))
        @notify_sleep = 0
        @exported_at = 0
        @opts = opts
        @opts[:ignore] = [/^\/\.git.*/, /^\/\.entangler.*/, /^\/\.idea.*/, /^\/log.*/, /^\/tmp.*/] unless @opts.has_key?(:ignore)
        validate_opts
        logger.info("Starting executor")
      end

      def generate_abs_path(rel_path)
        File.join(self.base_dir, rel_path)
      end

      def strip_base_path(path, base_dir = self.base_dir)
        File.expand_path(path).sub(base_dir, '')
      end

      def run
        start_notify_daemon
        start_local_io
        start_remote_io
        start_local_consumer
        logger.debug("NOTIFY PID: #{@notify_daemon_pid}")
        Signal.trap("INT") { kill_off_threads }
        wait_for_threads
      end

      protected
      def validate_opts
        raise "Base directory doesn't exist" unless Dir.exists?(self.base_dir)
      end

      def send_to_remote(msg = {})
        Marshal.dump(msg, @remote_writer)
      end

      def logger
        FileUtils::mkdir_p log_dir
        @logger ||= Logger.new(File.join(log_dir, 'entangler.log'))
      end

      def log_dir
        File.join(base_dir, '.entangler', 'log')
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
entangler-0.2.1 lib/entangler/executor/base.rb
entangler-0.2.0 lib/entangler/executor/base.rb
entangler-0.1.2 lib/entangler/executor/base.rb