2023-11-07 00:25:48 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class RepositoryItemDateReminderJob < ApplicationJob
|
|
|
|
queue_as :default
|
|
|
|
|
|
|
|
def perform
|
2023-12-01 22:00:30 +08:00
|
|
|
process_repository_values(RepositoryDateTimeValue, DateTime.current)
|
|
|
|
process_repository_values(RepositoryDateValue, Date.current)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def process_repository_values(model, comparison_value)
|
|
|
|
model
|
2024-01-08 22:23:16 +08:00
|
|
|
.joins(repository_cell: [:repository_row, { repository_column: :repository }])
|
|
|
|
.where(
|
|
|
|
notification_sent: false,
|
|
|
|
repositories: { type: 'Repository', archived: false },
|
|
|
|
repository_rows: { archived: false }
|
|
|
|
).where('repository_date_time_values.updated_at >= ?', 2.days.ago)
|
2023-12-08 01:13:21 +08:00
|
|
|
.where( # date(time) values that are within the reminder range
|
|
|
|
"data <= " \
|
|
|
|
"(?::timestamp + CAST(((repository_columns.metadata->>'reminder_unit')::int * " \
|
|
|
|
"(repository_columns.metadata->>'reminder_value')::int) || ' seconds' AS Interval))",
|
|
|
|
comparison_value
|
|
|
|
).find_each do |value|
|
2023-12-11 18:28:24 +08:00
|
|
|
repository_row = RepositoryRow.find(value.repository_cell.repository_row_id)
|
|
|
|
repository_column = RepositoryColumn.find(value.repository_cell.repository_column_id)
|
|
|
|
|
2023-12-01 22:00:30 +08:00
|
|
|
RepositoryItemDateNotification
|
2023-12-11 18:28:24 +08:00
|
|
|
.send_notifications({
|
|
|
|
"#{value.class.name.underscore}_id": value.id,
|
|
|
|
repository_row_id: repository_row.id,
|
|
|
|
repository_row_name: repository_row.name,
|
|
|
|
repository_column_id: repository_column.id,
|
|
|
|
repository_column_name: repository_column.name,
|
|
|
|
reminder_unit: repository_column.metadata['reminder_unit'],
|
|
|
|
reminder_value: repository_column.metadata['reminder_value']
|
|
|
|
})
|
2023-12-01 22:00:30 +08:00
|
|
|
end
|
2023-11-07 00:25:48 +08:00
|
|
|
end
|
|
|
|
end
|