Sha256: 1e1402d5b0c6d7bf64ad8048bcf822a2ffb12a2eceb0a0407774feaee6335d19

Contents?: true

Size: 758 Bytes

Versions: 162

Compression:

Stored size: 758 Bytes

Contents

# frozen_string_literal: true

module Motor
  module Configs
    module WriteToFile
      THREAD_POOL = Concurrent::FixedThreadPool.new(1)

      module_function

      def call
        return if Rails.env.test?
        return if THREAD_POOL.queue_length.positive?

        THREAD_POOL.post do
          ActiveRecord::Base.logger.silence do
            write_with_lock
          end
        rescue StandardError => e
          Rails.logger.error(e)
        end
      end

      def write_with_lock
        File.open(Motor::Configs.file_path, 'w') do |file|
          file.flock(File::LOCK_EX)

          YAML.dump(Motor::Configs::BuildConfigsHash.call, file)

          file.flock(File::LOCK_UN)

          file
        end.close
      end
    end
  end
end

Version data entries

162 entries across 162 versions & 7 rubygems

Version Path
motor-admin-0.4.34 lib/motor/configs/write_to_file.rb
motor-admin-0.4.33 lib/motor/configs/write_to_file.rb
motor-admin-0.4.32 lib/motor/configs/write_to_file.rb
motor-admin-0.4.31 lib/motor/configs/write_to_file.rb
motor-admin-0.4.30 lib/motor/configs/write_to_file.rb
motor-admin-0.4.29 lib/motor/configs/write_to_file.rb
motor-admin-0.4.28 lib/motor/configs/write_to_file.rb
motor-admin-cstham8-0.4.35 lib/motor/configs/write_to_file.rb
motor-admin-cstham8-0.4.34 lib/motor/configs/write_to_file.rb
motor-admin-cstham8-0.4.33 lib/motor/configs/write_to_file.rb
motor-admin-cstham8-0.4.32 lib/motor/configs/write_to_file.rb
motor-admin-cstham8-0.4.31 lib/motor/configs/write_to_file.rb
motor-admin-cstham8-0.4.30 lib/motor/configs/write_to_file.rb
motor-admin-cstham8-0.4.29 lib/motor/configs/write_to_file.rb
motor-admin-cstham8-0.4.28 lib/motor/configs/write_to_file.rb
motor-admin-cstham8-0.4.27 lib/motor/configs/write_to_file.rb
motor-admin-0.4.27 lib/motor/configs/write_to_file.rb
motor-admin-unosquare-0.4.28 lib/motor/configs/write_to_file.rb
motor-admin-unosquare-0.4.27 lib/motor/configs/write_to_file.rb
motor-admin-pz-0.4.26 lib/motor/configs/write_to_file.rb