Sha256: 69b3788a3679a0a9001b5b7e00fc371ac748b31781b5871211193853a1fc8a16

Contents?: true

Size: 868 Bytes

Versions: 3

Compression:

Stored size: 868 Bytes

Contents

# frozen_string_literal: true

require_relative 'config'
require_relative 'logging'
require_relative 'preamble'
require_relative 'globals'
require_relative 'task'

class INat::Application

  include INat::App
  include INat::App::Preamble

  def logger
    G.logger
  end

  def initialize
    setup!
    G.config = @config.freeze
    G.logger = INat::App::Logger::new self
  end

  private def tasks!
    @tasks = Queue::new
    @files.each do |file|
      @tasks.push Task::new(self, file)
    end
  end

  private def start!
    @threads = []
    count = [ @tasks.size, G.config[:threads][:tasks] ].min
    count.times do
      @threads << Thread.start do
        while !@tasks.empty?
          task = @tasks.pop
          task.execute
        end
      end
    end
    @threads.each { |th| th.join }
  end

  def run
    preamble!
    tasks!
    start!
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
inat-get-0.8.0.15 lib/inat/app/application.rb
inat-get-0.8.0.14 lib/inat/app/application.rb
inat-get-0.8.0.13 lib/inat/app/application.rb