<commit_before>class ReservationWorker
  include Sidekiq::Worker

  sidekiq_options :retry => false

  attr_accessor :reservation, :reservation_id

  def perform(reservation_id, action)
    @reservation_id = reservation_id
    @reservation = Reservation.find(reservation_id)
    begin
      $lock.synchronize("#{action}-reservation-#{reservation_id}", retries: 1, expiry: 2.minutes) do
        server = reservation.server
        server.send("#{action}_reservation", reservation)
      end
    rescue Exception => exception
      Rails.logger.error "Something went wrong #{action}-ing the server for reservation #{reservation_id} - #{exception}"
      Raven.capture_exception(exception) if Rails.env.production?
    ensure
      send("after_#{action}_reservation_steps") if reservation
      Rails.logger.info "#{action.capitalize}ed reservation: #{reservation}"
    end
  end

  def after_start_reservation_steps
    reservation.provisioned = true
    reservation.save(:validate => false)
  end

  def after_update_reservation_steps
    reservation.inactive_minute_counter = 0
    reservation.save(:validate => false)
  end

  def after_end_reservation_steps
    reservation.ends_at  = Time.current
    reservation.ended    = true
    reservation.duration = reservation.ends_at.to_i - reservation.starts_at.to_i
    reservation.save(:validate => false)
    LogScanWorker.perform_async(reservation_id)
  end

end<commit_msg>run a full GC after every reservation action<commit_after>class ReservationWorker
  include Sidekiq::Worker

  sidekiq_options :retry => false

  attr_accessor :reservation, :reservation_id

  def perform(reservation_id, action)
    @reservation_id = reservation_id
    @reservation = Reservation.find(reservation_id)
    begin
      $lock.synchronize("#{action}-reservation-#{reservation_id}", retries: 1, expiry: 2.minutes) do
        server = reservation.server
        server.send("#{action}_reservation", reservation)
      end
    rescue Exception => exception
      Rails.logger.error "Something went wrong #{action}-ing the server for reservation #{reservation_id} - #{exception}"
      Raven.capture_exception(exception) if Rails.env.production?
    ensure
      send("after_#{action}_reservation_steps") if reservation
      Rails.logger.info "#{action.capitalize}ed reservation: #{reservation}"
      GC.start
    end
  end

  def after_start_reservation_steps
    reservation.provisioned = true
    reservation.save(:validate => false)
  end

  def after_update_reservation_steps
    reservation.inactive_minute_counter = 0
    reservation.save(:validate => false)
  end

  def after_end_reservation_steps
    reservation.ends_at  = Time.current
    reservation.ended    = true
    reservation.duration = reservation.ends_at.to_i - reservation.starts_at.to_i
    reservation.save(:validate => false)
    LogScanWorker.perform_async(reservation_id)
  end

end
{'fraction_non_alphanumeric': 0.09018659295093297, 'fraction_numerical': 0.002073255010366275, 'mean_word_length': 4.114840989399293, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '4101959', 'n_tokens_mistral': 880, 'n_tokens_neox': 844, 'n_words': 175}