You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: process_sync_events_service.rb
    path of file: ./repos/gitlabhq/app/services/ci
    
    the code of the file until where you have to start completion: # frozen_string_literal: true

module Ci
  class ProcessSyncEventsService
    include ExclusiveLeaseGu
    
    def process_events
      add_result(estimated_total_events: @sync_event_class.upper_bound_count)

      events = @sync_event_class.unprocessed_events.preload_synced_relation.first(BATCH_SIZE)

      add_result(consumable_events: events.size)

      return if events.empty?

      processed_events = []

      begin
        events.each do |event|
          @sync_class.sync!(event)

          processed_events << event
        end
      ensure
        add_result(processed_events: processed_events.size)
        @sync_event_class.mark_records_processed(processed_events)
      end