Class: PgEventstore::Subscription
- Inherits:
-
Object
- Object
- PgEventstore::Subscription
- Includes:
- Extensions::OptionsExtension
- Defined in:
- lib/pg_eventstore/subscriptions/subscription.rb
Overview
Defines ruby’s representation of subscriptions record.
Constant Summary collapse
- DEFAULT_TIMESTAMP =
Time.at(0).utc.freeze
Instance Attribute Summary collapse
-
#average_event_processing_time ⇒ Float?
A speed of the subscription.
-
#chunk_query_interval ⇒ Integer, ...
Determines how often to pull events for the given Subscription in seconds.
- #created_at ⇒ Time?
-
#current_position ⇒ Integer?
Current Subscription’s position.
- #id ⇒ Integer?
-
#last_chunk_fed_at ⇒ Time?
Shows the time when last time events were fed to the event’s processor.
-
#last_chunk_greatest_position ⇒ Integer?
Shows the greatest global_position of the last event in the last chunk fed to the event’s processor.
-
#last_error ⇒ Hash?
The information about last error caused when processing events by the Subscription.
-
#last_error_occurred_at ⇒ Time?
The time when the last error occurred.
-
#last_restarted_at ⇒ Time?
Last time the Subscription was restarted.
-
#locked_by ⇒ Integer?
The id of subscription manager which obtained the lock of the Subscription.
-
#max_restarts_number ⇒ Integer?
Maximum number of times the Subscription can be restarted.
-
#name ⇒ String?
Subscription’s name.
-
#options ⇒ Hash?
Subscription’s options to be used to query events.
-
#restart_count ⇒ Integer?
The number of Subscription’s restarts after its failure.
-
#set ⇒ String?
Subscription’s set.
-
#state ⇒ String?
Current Subscription’s state.
-
#time_between_restarts ⇒ Integer?
Interval in seconds between retries of failed Subscription.
-
#total_processed_events ⇒ Integer?
Total number of events, processed by this subscription.
- #updated_at ⇒ Time?
Class Method Summary collapse
- .ping_all(subscriptions_set_id, subscriptions) ⇒ void
- .subscription_queries ⇒ PgEventstore::SubscriptionQueries
Instance Method Summary collapse
- #==(other) ⇒ Boolean
- #assign_attributes(attrs) ⇒ Hash
-
#dup ⇒ PgEventstore::Subscription
Dup the current object without assigned connection.
- #eql?(other) ⇒ Boolean
- #hash ⇒ Integer
-
#lock!(lock_id, force: false) ⇒ PgEventstore::Subscription
Locks the Subscription by the given lock id.
- #reload ⇒ PgEventstore::Subscription
- #update(attrs) ⇒ Hash
Methods included from Extensions::OptionsExtension
included, #initialize, #options_hash, #readonly!, #readonly?
Instance Attribute Details
#average_event_processing_time ⇒ Float?
Returns a speed of the subscription. Divide 1 by this value to determine how much events are processed by the Subscription per second.
49 |
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 49 attribute(:average_event_processing_time) |
#chunk_query_interval ⇒ Integer, ...
Returns determines how often to pull events for the given Subscription in seconds.
71 |
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 71 attribute(:chunk_query_interval) |
#created_at ⇒ Time?
85 |
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 85 attribute(:created_at) |
#current_position ⇒ Integer?
Returns current Subscription’s position. It is updated automatically each time an event is processed.
41 |
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 41 attribute(:current_position) |
#id ⇒ Integer?
24 |
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 24 attribute(:id) |
#last_chunk_fed_at ⇒ Time?
Returns shows the time when last time events were fed to the event’s processor.
74 |
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 74 attribute(:last_chunk_fed_at) |
#last_chunk_greatest_position ⇒ Integer?
Returns shows the greatest global_position of the last event in the last chunk fed to the event’s processor.
78 |
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 78 attribute(:last_chunk_greatest_position) |
#last_error ⇒ Hash?
Returns the information about last error caused when processing events by the Subscription.
65 |
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 65 attribute(:last_error) |
#last_error_occurred_at ⇒ Time?
Returns the time when the last error occurred.
68 |
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 68 attribute(:last_error_occurred_at) |
#last_restarted_at ⇒ Time?
Returns last time the Subscription was restarted.
61 |
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 61 attribute(:last_restarted_at) |
#locked_by ⇒ Integer?
Returns The id of subscription manager which obtained the lock of the Subscription. nil value means that the Subscription isn’t locked yet by any subscription manager.
82 |
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 82 attribute(:locked_by) |
#max_restarts_number ⇒ Integer?
Returns maximum number of times the Subscription can be restarted.
55 |
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 55 attribute(:max_restarts_number) |
#name ⇒ String?
Returns Subscription’s name. Subscription should have unique pair of set and name.
30 |
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 30 attribute(:name) |
#options ⇒ Hash?
Returns subscription’s options to be used to query events. See SubscriptionManager#subscribe for the list of available options.
37 |
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 37 attribute(:options) |
#restart_count ⇒ Integer?
Returns the number of Subscription’s restarts after its failure.
52 |
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 52 attribute(:restart_count) |
#set ⇒ String?
Returns Subscription’s set. Subscription should have unique pair of set and name.
27 |
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 27 attribute(:set) |
#state ⇒ String?
Returns current Subscription’s state. It is updated automatically during Subscription’s life cycle See RunnerState::STATES for possible values.
45 |
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 45 attribute(:state) |
#time_between_restarts ⇒ Integer?
Returns interval in seconds between retries of failed Subscription.
58 |
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 58 attribute(:time_between_restarts) |
#total_processed_events ⇒ Integer?
Returns total number of events, processed by this subscription.
33 |
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 33 attribute(:total_processed_events) |
#updated_at ⇒ Time?
88 |
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 88 attribute(:updated_at) |
Class Method Details
.ping_all(subscriptions_set_id, subscriptions) ⇒ void
This method returns an undefined value.
94 95 96 97 98 99 100 101 |
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 94 def ping_all(subscriptions_set_id, subscriptions) result = subscription_queries.ping_all(subscriptions_set_id, subscriptions.map(&:id)) subscriptions.each do |subscription| next unless result[subscription.id] subscription.assign_attributes(updated_at: result[subscription.id]) end end |
.subscription_queries ⇒ PgEventstore::SubscriptionQueries
104 105 106 |
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 104 def subscription_queries SubscriptionQueries.new(connection) end |
Instance Method Details
#==(other) ⇒ Boolean
165 166 167 168 169 |
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 165 def ==(other) return false unless other.is_a?(Subscription) id == other.id end |
#assign_attributes(attrs) ⇒ Hash
121 122 123 124 125 |
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 121 def assign_attributes(attrs) attrs.each do |attr, value| public_send("#{attr}=", value) end end |
#dup ⇒ PgEventstore::Subscription
Dup the current object without assigned connection
140 141 142 |
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 140 def dup Subscription.new(**Utils.deep_dup()) end |
#eql?(other) ⇒ Boolean
157 158 159 160 161 |
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 157 def eql?(other) return false unless other.is_a?(Subscription) hash == other.hash end |
#hash ⇒ Integer
151 152 153 |
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 151 def hash id.hash end |
#lock!(lock_id, force: false) ⇒ PgEventstore::Subscription
Locks the Subscription by the given lock id
131 132 133 134 135 136 |
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 131 def lock!(lock_id, force: false) self.id = subscription_queries.find_or_create_by(set: set, name: name)[:id] self.locked_by = subscription_queries.lock!(id, lock_id, force: force) reset_runtime_attributes self end |
#reload ⇒ PgEventstore::Subscription
145 146 147 148 |
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 145 def reload assign_attributes(subscription_queries.find!(id)) self end |
#update(attrs) ⇒ Hash
115 116 117 |
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 115 def update(attrs) assign_attributes(subscription_queries.update(id, attrs: attrs, locked_by: locked_by)) end |