From fd1b42bb89be6c9cb84ed6153f8dd3cd381df080 Mon Sep 17 00:00:00 2001 From: Max Wofford Date: Tue, 5 Aug 2025 12:25:15 -0400 Subject: [PATCH 1/3] Switch to instant mail queue for 7-day streak letter --- app/models/physical_mail.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/models/physical_mail.rb b/app/models/physical_mail.rb index d9e8304c..0cf3018d 100644 --- a/app/models/physical_mail.rb +++ b/app/models/physical_mail.rb @@ -14,6 +14,10 @@ class PhysicalMail < ApplicationRecord first_time_7_streak: 1 } + def self.instant_mission_types + %w[first_time_7_streak] + end + scope :pending_delivery, -> { where(status: :pending) .joins(:user) @@ -36,6 +40,11 @@ def deliver! return if status == :sent || theseus_id.present? slug = "hackatime-#{mission_type.to_s.gsub("_", "-")}" + endpoint = if self.class.instant_mission_types.include?(mission_type) + "https://mail.hackclub.com/api/v1/letter_queues/instant/#{slug}-instant" + else + "https://mail.hackclub.com/api/v1/letter_queues/#{slug}" + end flavors = FlavorText.compliment flavors.concat(FlavorText.rare_compliment) if rand(10) == 0 @@ -43,7 +52,7 @@ def deliver! return nil unless user.mailing_address.present? # authorization: Bearer - response = HTTP.auth("Bearer #{ENV["MAIL_HACKCLUB_TOKEN"]}").post("https://mail.hackclub.com/api/v1/letter_queues/#{slug}", json: { + response = HTTP.auth("Bearer #{ENV["MAIL_HACKCLUB_TOKEN"]}").post(endpoint, json: { recipient_email: user.email_addresses.first.email, address: { first_name: user.mailing_address.first_name, From db175abf9761baf514231b07d6be30d4680fdcbe Mon Sep 17 00:00:00 2001 From: Max Wofford Date: Tue, 5 Aug 2025 12:54:21 -0400 Subject: [PATCH 2/3] Ignore coolify ssl errors on physical mail delivery --- app/models/physical_mail.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/models/physical_mail.rb b/app/models/physical_mail.rb index 0cf3018d..dfb0ef8f 100644 --- a/app/models/physical_mail.rb +++ b/app/models/physical_mail.rb @@ -79,6 +79,9 @@ def deliver! update(status: :failed) raise "Failed to deliver physical mail: #{response.body}" end + rescue OpenSSL::SSL::SSLError => e + Rails.logger.warn "SSL error during mail delivery (request likely succeeded): #{e.message}" + update(status: :sent) rescue => e update(status: :failed) raise e From 8522490d12a766dd9bd9f9eec011d76543f91f4d Mon Sep 17 00:00:00 2001 From: Max Wofford Date: Tue, 5 Aug 2025 12:54:42 -0400 Subject: [PATCH 3/3] Re-enable physical mail job in cron --- config/initializers/good_job.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/config/initializers/good_job.rb b/config/initializers/good_job.rb index 313a0357..fa395f2e 100644 --- a/config/initializers/good_job.rb +++ b/config/initializers/good_job.rb @@ -124,10 +124,10 @@ cron: "0 * * * *", # Run before AttemptToDeliverPhysicalMailJob class: "CheckStreakPhysicalMailJob" }, - # attempt_to_deliver_physical_mail: { - # cron: "5 * * * *", # Run after physical mail is created - # class: "AttemptToDeliverPhysicalMailJob" - # }, + attempt_to_deliver_physical_mail: { + cron: "5 * * * *", # Run after physical mail is created + class: "AttemptToDeliverPhysicalMailJob" + }, sync_neighborhood_from_airtable: { cron: "*/15 * * * *", class: "Neighborhood::SyncFromAirtableJob"