Sha256: d758b83c9ebe51cb2aa7a221b4972e44df942ab27392b80f90c1c3c434f72758

Contents?: true

Size: 556 Bytes

Versions: 10

Compression:

Stored size: 556 Bytes

Contents

# frozen_string_literal: true

module TasksScheduler
  class Info
    TASKS_LIMIT_KEY = 'TASKS_SCHEDULER_TASKS_LIMIT'
    TASKS_LIMIT_DEFAULT_VALUE = '-1'

    class << self
      def can_run_new_task?
        return true if tasks_running_limit.negative?

        tasks_running_current < tasks_running_limit
      end

      def tasks_running_current
        ::ScheduledTask.all.select(&:process_running?).count
      end

      def tasks_running_limit
        ENV[TASKS_LIMIT_KEY].if_present(TASKS_LIMIT_DEFAULT_VALUE, &:to_i)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
tasks_scheduler-0.6.9 lib/tasks_scheduler/info.rb
tasks_scheduler-0.6.8 lib/tasks_scheduler/info.rb
tasks_scheduler-0.6.7 lib/tasks_scheduler/info.rb
tasks_scheduler-0.6.6 lib/tasks_scheduler/info.rb
tasks_scheduler-0.6.5 lib/tasks_scheduler/info.rb
tasks_scheduler-0.6.4 lib/tasks_scheduler/info.rb
tasks_scheduler-0.6.3 lib/tasks_scheduler/info.rb
tasks_scheduler-0.6.2 lib/tasks_scheduler/info.rb
tasks_scheduler-0.6.1 lib/tasks_scheduler/info.rb
tasks_scheduler-0.6.0 lib/tasks_scheduler/info.rb