<commit_before>class OsmUpdateJob < OsmCommonJob

  def self.enqueue(element_id, element_type, user_id, place_id, tags)
    # Do not enqeue job if not in production or test environment
    # return if Rails.env.development?
    return unless Rails.env.production? || Rails.env.test?

    # Remove wheelchair tag if value is "unknown"
    tags.delete("wheelchair") if tags["wheelchair"] == 'unknown'

    new(element_id, element_type, user_id, place_id, tags).tap do |job|
      Delayed::Job.enqueue(job, :queue => 'osm')
    end
  end

  def perform
    begin
      osm_element   = update_element(element_type, element_id, tags)
      osm_changeset = find_or_create_changeset(user, place.data_set_id)
      api.save(osm_element, osm_changeset)
      Place.where(id: place_id).update_all({osm_id: element_id, osm_type: element_type, matcher_id: user_id})
    rescue Rosemary::Conflict => conflict
      # Catch exception and ignore it, so the job thinks it was successful.
      logger.info "IGNORE: #{element_type}:#{element_id} nothing has changed!"
    end
  end

  def update_element(element_type, element_id, tags)
    element_from_osm = api.find_element(element_type, element_id)
    element_copy = element_from_osm.dup
    element_copy.tags.merge!(tags)

    # Use spaceship operator for comparision:
    # as "element_copy == element_from_osm" is false because of object_id
    comparison_value = (element_from_osm <=> element_copy)

    # Ignore this job, as there are no changes to be saved
    raise Rosemary::Conflict.new('NotChanged') if comparison_value == 0
    element_copy
  end

  def before(job)
    logger.debug("Starting OsmUpdateJob: #{job.id} >>>>>>>>>>>>>>>>>>>>>>>>")
    raise ArgumentError.new("Client cannot be nil") if client.nil?
  end

  def after(job)
    logger.debug("Finished OsmUpdateJob: #{job.id} <<<<<<<<<<<<<<<<<<<<<<<<")
  end

  def success(job)
    logger.debug("Hoooray, success!")
  end

  def error(job,exception)
    logger.error(exception.message)
  end

  def failure(job)
  end

end<commit_msg>Reorder methods.<commit_after>class OsmUpdateJob < OsmCommonJob

  def self.enqueue(element_id, element_type, user_id, place_id, tags)
    # Do not enqeue job if not in production or test environment
    # return if Rails.env.development?
    return unless Rails.env.production? || Rails.env.test?

    # Remove wheelchair tag if value is "unknown"
    tags.delete("wheelchair") if tags["wheelchair"] == 'unknown'

    new(element_id, element_type, user_id, place_id, tags).tap do |job|
      Delayed::Job.enqueue(job, :queue => 'osm')
    end
  end

  def perform
    begin
      osm_element   = update_element(element_type, element_id, tags)
      osm_changeset = find_or_create_changeset(user, place.data_set_id)
      api.save(osm_element, osm_changeset)
      Place.where(id: place_id).update_all({osm_id: element_id, osm_type: element_type, matcher_id: user_id})
    rescue Rosemary::Conflict => conflict
      # Catch exception and ignore it, so the job thinks it was successful.
      logger.info "IGNORE: #{element_type}:#{element_id} nothing has changed!"
    end
  end

  def update_element(element_type, element_id, tags)
    element_from_osm = api.find_element(element_type, element_id)
    element_copy = element_from_osm.dup
    element_copy.tags.merge!(tags)

    # Use spaceship operator for comparision:
    # as "element_copy == element_from_osm" is false because of object_id
    comparison_value = (element_from_osm <=> element_copy)

    # Ignore this job, as there are no changes to be saved
    raise Rosemary::Conflict.new('NotChanged') if comparison_value == 0
    element_copy
  end

  def before(job)
    logger.debug("Starting OsmUpdateJob: #{job.id} >>>>>>>>>>>>>>>>>>>>>>>>")
    raise ArgumentError.new("Client cannot be nil") if client.nil?
  end

  def success(job)
    logger.debug("Hoooray, success!")
  end

  def error(job,exception)
    logger.error(exception.message)
  end

  def after(job)
    logger.debug("Finished OsmUpdateJob: #{job.id} <<<<<<<<<<<<<<<<<<<<<<<<")
  end

  def failure(job)
  end

end
{'fraction_non_alphanumeric': 0.11958914159941306, 'fraction_numerical': 0.0004891171435558817, 'mean_word_length': 4.0431565967940815, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 57, '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': '2196847', 'n_tokens_mistral': 1367, 'n_tokens_neox': 1318, 'n_words': 338}