Class: Gcpc::Interceptors::Subscriber::CheckOrderInterceptor::BaseStrategy

Inherits:
Object
  • Object
show all
Defined in:
lib/gcpc/interceptors/subscriber/check_order_interceptor.rb

Constant Summary collapse

DEFAULT_TIMESTAMP_KEY =
"published_at"
DEFAULT_TTL =

7 days

7 * 24 * 3600

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ttl: DEFAULT_TTL, timestamp_key: DEFAULT_TIMESTAMP_KEY) ⇒ BaseStrategy

Returns a new instance of BaseStrategy.



12
13
14
15
# File 'lib/gcpc/interceptors/subscriber/check_order_interceptor.rb', line 12

def initialize(ttl: DEFAULT_TTL, timestamp_key: DEFAULT_TIMESTAMP_KEY)
  @ttl           = ttl
  @timestamp_key = DEFAULT_TIMESTAMP_KEY
end

Instance Attribute Details

#ttlObject (readonly)

Returns the value of attribute ttl.



17
18
19
# File 'lib/gcpc/interceptors/subscriber/check_order_interceptor.rb', line 17

def ttl
  @ttl
end

Instance Method Details

#decode_timestamp(str) ⇒ DateTime?

Parameters:

  • str (String)

Returns:

  • (DateTime, nil)


29
30
31
32
33
# File 'lib/gcpc/interceptors/subscriber/check_order_interceptor.rb', line 29

def decode_timestamp(str)
  DateTime.parse(str)
rescue ArgumentError, TypeError
  nil
end

#group_id(data, attributes, message) ⇒ String

Parameters:

  • data (String)
  • attributes (Hash)
  • message (Google::Cloud::Pubsub::ReceivedMessage)

Returns:

  • (String)


39
40
41
42
43
44
# File 'lib/gcpc/interceptors/subscriber/check_order_interceptor.rb', line 39

def group_id(data, attributes, message)
  # The default behavior is to always return the same key. This means
  # that all messages should be in order. If you want to change the
  # set of messages you want to order, please override this method.
  "same-id"
end

#on_swapped(data, attributes, message, &block) {|data, attributes, message| ... } ⇒ Object

Parameters:

  • data (String)
  • attributes (Hash)
  • message (Google::Cloud::Pubsub::ReceivedMessage)
  • block (Proc)

Yields:

  • (data, attributes, message)


50
51
52
53
# File 'lib/gcpc/interceptors/subscriber/check_order_interceptor.rb', line 50

def on_swapped(data, attributes, message, &block)
  # By default, simply yield
  yield data, attributes, message
end

#timestamp(data, attributes, message) ⇒ String?

Parameters:

  • data (String)
  • attributes (Hash)
  • message (Google::Cloud::Pubsub::ReceivedMessage)

Returns:

  • (String, nil)


23
24
25
# File 'lib/gcpc/interceptors/subscriber/check_order_interceptor.rb', line 23

def timestamp(data, attributes, message)
  attributes[@timestamp_key]
end