Class: Karafka::Pro::ScheduledMessages::Day

Inherits:
Object
  • Object
show all
Defined in:
lib/karafka/pro/scheduled_messages/day.rb

Overview

Just a simple UTC day implementation. Since we operate on a scope of one day, this allows us to encapsulate when given day ends

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDay

Returns a new instance of Day.



29
30
31
32
33
34
35
36
# File 'lib/karafka/pro/scheduled_messages/day.rb', line 29

def initialize
  @created_at = Time.now.to_i

  time = Time.at(@created_at).utc

  @starts_at = Time.utc(time.year, time.month, time.day).to_i
  @ends_at = @starts_at + 86_399
end

Instance Attribute Details

#created_atInteger (readonly)

Returns utc timestamp when this day object was created. Keep in mind, that this is not when the day started but when this object was created.

Returns:

  • (Integer)

    utc timestamp when this day object was created. Keep in mind, that this is not when the day started but when this object was created.



22
23
24
# File 'lib/karafka/pro/scheduled_messages/day.rb', line 22

def created_at
  @created_at
end

#ends_atInteger (readonly)

Equal to 23:59:59.

Returns:

  • (Integer)

    utc timestamp when this day ends (last second of day).



25
26
27
# File 'lib/karafka/pro/scheduled_messages/day.rb', line 25

def ends_at
  @ends_at
end

#starts_atInteger (readonly)

Returns utc timestamp when this day starts. Equal to 00:00:00.

Returns:

  • (Integer)

    utc timestamp when this day starts. Equal to 00:00:00



27
28
29
# File 'lib/karafka/pro/scheduled_messages/day.rb', line 27

def starts_at
  @starts_at
end

Instance Method Details

#ended?Boolean

Returns did the current day we operate on ended.

Returns:

  • (Boolean)

    did the current day we operate on ended.



39
40
41
# File 'lib/karafka/pro/scheduled_messages/day.rb', line 39

def ended?
  @ends_at < Time.now.to_i
end