Sha256: 4cad1b1d4e61a7e853d3fb8528d99c2351f49b77abda038b575e989127caba38
Contents?: true
Size: 1.51 KB
Versions: 1
Compression:
Stored size: 1.51 KB
Contents
# frozen_string_literal: true module Tobox module Plugins module EventGrouping def self.configure(conf) conf.config[:group_column] = :group_id end module FetcherMethods def initialize(_, configuration) super @group_column = configuration[:group_column] end private def fetch_event_ids group = @pick_next_sql.for_update .skip_locked .limit(1) .select(@group_column) # get total from a group, to compare to the number of future locked rows. total_from_group = @ds.where(@group_column => group).count event_ids = @ds.where(@group_column => group) event_ids = if @configuration.visibility_type_bool? event_ids.order(:id) else event_ids.order(Sequel.desc(@visibility_column, nulls: :first), :id) end event_ids = event_ids.for_update.skip_locked.select_map(:id) if event_ids.size != total_from_group # this happens if concurrent workers locked different rows from the same group, # or when new rows from a given group have been inserted after the lock has been # acquired event_ids = [] end # lock all event_ids.first(@batch_size) end end end register_plugin :event_grouping, EventGrouping end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
tobox-0.7.0 | lib/tobox/plugins/event_grouping.rb |