fix: use utc timestamps when determining raw table names

This commit is contained in:
Adam Cooke
2024-02-01 16:41:41 +00:00
parent 8794a2f447
commit ce19bf7988
3 changed files with 4 additions and 4 deletions
+1 -1
View File
@@ -107,7 +107,7 @@ module Postal
#
# Insert a new raw message into a table (creating it if needed)
#
def insert_raw_message(data, date = Date.today)
def insert_raw_message(data, date = Time.now.utc.to_date)
table_name = raw_table_name_for_date(date)
begin
headers, body = data.split(/\r?\n\r?\n/, 2)
+1 -1
View File
@@ -263,7 +263,7 @@ module Postal
return unless @pending_raw_message
self.size = @pending_raw_message.bytesize
date = Date.today
date = Time.now.utc.to_date
table_name, headers_id, body_id = @database.insert_raw_message(@pending_raw_message, date)
self.raw_table = table_name
self.raw_headers_id = headers_id
+2 -2
View File
@@ -94,7 +94,7 @@ module Postal
# Return a list of raw message tables that are older than the given date
#
def raw_tables(max_age = 30)
earliest_date = max_age ? Date.today - max_age : nil
earliest_date = max_age ? Time.now.utc.to_date - max_age : nil
[].tap do |tables|
@database.query("SHOW TABLES FROM `#{@database.database_name}` LIKE 'raw-%'").each do |tbl|
tbl_name = tbl.to_a.first.last
@@ -128,7 +128,7 @@ module Postal
#  Remove messages from the messages table that are too old to retain
#
def remove_messages(max_age = 60)
time = (Date.today - max_age.days).to_time.end_of_day
time = (Time.now.utc.to_date - max_age.days).to_time.end_of_day
return unless newest_message_to_remove = @database.select(:messages, where: { timestamp: { less_than_or_equal_to: time.to_f } }, limit: 1, order: :id, direction: "DESC", fields: [:id]).first
id = newest_message_to_remove["id"]