<commit_before>class SchedulingInfrastructureMonitoringService

  def initialize(infrastructure_id, user_id, time_delay)
    @infrastructure_id = infrastructure_id.to_s
    @user_id = user_id.to_s
    @time_delay = time_delay
  end

  def run
    Rails.logger.info("[SchedulingInfrastructureMonitoringService] infra: #{@infrastructure_id}, user: #{@user_id}")

    Scalarm::MongoLock.mutex("user-#{@user_id}-monitoring") do
      user = ScalarmUser.where(id: @user_id).first

      unless user.monitoring_scheduled?(@infrastructure_id)
        Rails.logger.info("Scheduling another SimMonitorWorker - #{@infrastructure_id} - #{@user_id}")

        if @time_delay.nil?
          SimMonitorWorker.perform_async(@infrastructure_id, @user_id)
        else
          SimMonitorWorker.perform_in(@time_delay, @infrastructure_id, @user_id)
        end

        user.set_monitoring_scheduled(@infrastructure_id)
        user.save
      else
        Rails.logger.info("There is no need to schedule another SimMonitorWorker - #{@infrastructure_id} - #{@user_id}")
      end
    end
  end

end<commit_msg>Fixing infrastructure view: private clusters are shown only to owners.<commit_after>class SchedulingInfrastructureMonitoringService

  def initialize(infrastructure_id, user_id, time_delay)
    Rails.logger.info("[SchedulingInfrastructureMonitoringService] INIT infra: #{infrastructure_id}, user: #{user_id}, delay: #{time_delay}")

    @infrastructure_id = infrastructure_id.to_s
    @user_id = user_id.to_s
    @time_delay = time_delay
  end

  def run
    Rails.logger.info("[SchedulingInfrastructureMonitoringService] RUN infra: #{@infrastructure_id}, user: #{@user_id}, delay: #{@time_delay}")

    Scalarm::MongoLock.mutex("user-#{@user_id}-monitoring") do
      user = ScalarmUser.where(id: @user_id).first

      unless user.monitoring_scheduled?(@infrastructure_id)
        Rails.logger.info("Scheduling another SimMonitorWorker - #{@infrastructure_id} - #{@user_id}")

        if @time_delay.nil?
          Rails.logger.info("[SchedulingInfrastructureMonitoringService] ASYNC infra: #{@infrastructure_id}, user: #{@user_id}, delay: #{@time_delay}")
          SimMonitorWorker.perform_async(@infrastructure_id, @user_id)
        else
          Rails.logger.info("[SchedulingInfrastructureMonitoringService] DELAY infra: #{@infrastructure_id}, user: #{@user_id}, delay: #{@time_delay}")
          SimMonitorWorker.perform_in(@time_delay, @infrastructure_id, @user_id)
        end

        user.set_monitoring_scheduled(@infrastructure_id)
        user.save
      else
        Rails.logger.info("There is no need to schedule another SimMonitorWorker - #{@infrastructure_id} - #{@user_id}")
      end
    end
  end

end
{'fraction_non_alphanumeric': 0.11254137550570062, 'fraction_numerical': 0.0, 'mean_word_length': 4.2007648183556405, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6958920', 'n_tokens_mistral': 847, 'n_tokens_neox': 834, 'n_words': 151}