Class: PgEventstore::Subscription

Inherits:
Object
  • Object
show all
Includes:
Extensions::OptionsExtension
Defined in:
lib/pg_eventstore/subscriptions/subscription.rb

Overview

Defines ruby’s representation of subscriptions record.

Constant Summary collapse

DEFAULT_TIMESTAMP =

Returns:

  • (Time)
Time.at(0).utc.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Extensions::OptionsExtension

included, #initialize, #options_hash, #readonly!, #readonly?

Instance Attribute Details

#average_event_processing_timeFloat?

Returns a speed of the subscription. Divide 1 by this value to determine how much events are processed by the Subscription per second.

Returns:

  • (Float, nil)

    a speed of the subscription. Divide 1 by this value to determine how much events are processed by the Subscription per second.



39
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 39

attribute(:average_event_processing_time)

#chunk_query_intervalInteger, ...

Returns determines how often to pull events for the given Subscription in seconds.

Returns:

  • (Integer, Float, nil)

    determines how often to pull events for the given Subscription in seconds



61
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 61

attribute(:chunk_query_interval)

#created_atTime?

Returns:

  • (Time, nil)


75
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 75

attribute(:created_at)

#current_positionInteger?

Returns current Subscription’s position. It is updated automatically each time an event is processed.

Returns:

  • (Integer, nil)

    current Subscription’s position. It is updated automatically each time an event is processed



31
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 31

attribute(:current_position)

#idInteger?

Returns:

  • (Integer, nil)


14
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 14

attribute(:id)

#last_chunk_fed_atTime?

Returns shows the time when last time events were fed to the event’s processor.

Returns:

  • (Time, nil)

    shows the time when last time events were fed to the event’s processor



64
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 64

attribute(:last_chunk_fed_at)

#last_chunk_greatest_positionInteger?

Returns shows the greatest global_position of the last event in the last chunk fed to the event’s processor.

Returns:

  • (Integer, nil)

    shows the greatest global_position of the last event in the last chunk fed to the event’s processor



68
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 68

attribute(:last_chunk_greatest_position)

#last_errorHash?

Returns the information about last error caused when processing events by the Subscription.

Returns:

  • (Hash, nil)

    the information about last error caused when processing events by the Subscription.



55
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 55

attribute(:last_error)

#last_error_occurred_atTime?

Returns the time when the last error occurred.

Returns:

  • (Time, nil)

    the time when the last error occurred



58
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 58

attribute(:last_error_occurred_at)

#last_restarted_atTime?

Returns last time the Subscription was restarted.

Returns:

  • (Time, nil)

    last time the Subscription was restarted



51
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 51

attribute(:last_restarted_at)

#locked_byInteger?

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.

Returns:

  • (Integer, nil)

    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.



72
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 72

attribute(:locked_by)

#max_restarts_numberInteger?

Returns maximum number of times the Subscription can be restarted.

Returns:

  • (Integer, nil)

    maximum number of times the Subscription can be restarted



45
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 45

attribute(:max_restarts_number)

#nameString?

Returns Subscription’s name. Subscription should have unique pair of set and name.

Returns:

  • (String, nil)

    Subscription’s name. Subscription should have unique pair of set and name.



20
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 20

attribute(:name)

#optionsHash?

Returns subscription’s options to be used to query events. See SubscriptionManager#subscribe for the list of available options.

Returns:

  • (Hash, nil)

    subscription’s options to be used to query events. See SubscriptionManager#subscribe for the list of available options



27
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 27

attribute(:options)

#restart_countInteger?

Returns the number of Subscription’s restarts after its failure.

Returns:

  • (Integer, nil)

    the number of Subscription’s restarts after its failure



42
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 42

attribute(:restart_count)

#setString?

Returns Subscription’s set. Subscription should have unique pair of set and name.

Returns:

  • (String, nil)

    Subscription’s set. Subscription should have unique pair of set and name.



17
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 17

attribute(:set)

#stateString?

Returns current Subscription’s state. It is updated automatically during Subscription’s life cycle See RunnerState::STATES for possible values.

Returns:

  • (String, nil)

    current Subscription’s state. It is updated automatically during Subscription’s life cycle See RunnerState::STATES for possible values.



35
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 35

attribute(:state)

#time_between_restartsInteger?

Returns interval in seconds between retries of failed Subscription.

Returns:

  • (Integer, nil)

    interval in seconds between retries of failed Subscription



48
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 48

attribute(:time_between_restarts)

#total_processed_eventsInteger?

Returns total number of events, processed by this subscription.

Returns:

  • (Integer, nil)

    total number of events, processed by this subscription



23
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 23

attribute(:total_processed_events)

#updated_atTime?

Returns:

  • (Time, nil)


78
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 78

attribute(:updated_at)

Class Method Details

.ping_all(subscriptions_set_id, subscriptions) ⇒ void

This method returns an undefined value.

Parameters:



84
85
86
87
88
89
90
91
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 84

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_queriesPgEventstore::SubscriptionQueries

Returns:

  • (PgEventstore::SubscriptionQueries)


94
95
96
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 94

def subscription_queries
  SubscriptionQueries.new(connection)
end

Instance Method Details

#==(other) ⇒ Boolean

Parameters:

  • other (Object)

Returns:

  • (Boolean)


155
156
157
158
159
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 155

def ==(other)
  return false unless other.is_a?(Subscription)

  id == other.id
end

#assign_attributes(attrs) ⇒ Hash

Parameters:

  • attrs (Hash)

Returns:

  • (Hash)


111
112
113
114
115
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 111

def assign_attributes(attrs)
  attrs.each do |attr, value|
    public_send("#{attr}=", value)
  end
end

#dupPgEventstore::Subscription

Dup the current object without assigned connection



130
131
132
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 130

def dup
  Subscription.new(**Utils.deep_dup(options_hash))
end

#eql?(other) ⇒ Boolean

Parameters:

  • other (Object)

Returns:

  • (Boolean)


147
148
149
150
151
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 147

def eql?(other)
  return false unless other.is_a?(Subscription)

  hash == other.hash
end

#hashInteger

Returns:

  • (Integer)


141
142
143
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 141

def hash
  id.hash
end

#lock!(lock_id, force: false) ⇒ PgEventstore::Subscription

Locks the Subscription by the given lock id

Parameters:

  • lock_id (Integer)

    SubscriptionsSet#id

  • force (Boolean) (defaults to: false)

Returns:



121
122
123
124
125
126
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 121

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

#reloadPgEventstore::Subscription



135
136
137
138
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 135

def reload
  assign_attributes(subscription_queries.find!(id))
  self
end

#update(attrs) ⇒ Hash

Parameters:

  • attrs (Hash)

Returns:

  • (Hash)


105
106
107
# File 'lib/pg_eventstore/subscriptions/subscription.rb', line 105

def update(attrs)
  assign_attributes(subscription_queries.update(id, attrs: attrs, locked_by: locked_by))
end