Skip to content

Commit

Permalink
add waiting list mailer
Browse files Browse the repository at this point in the history
  • Loading branch information
loftwah committed Sep 4, 2024
1 parent 7be0e2b commit 2e15cb1
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/jobs/send_waiting_list_report_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# app/jobs/send_waiting_list_report_job.rb
class SendWaitingListReportJob < ApplicationJob
queue_as :default

def perform
WaitingListMailer.daily_report('[email protected]').deliver_now
end
end
13 changes: 13 additions & 0 deletions app/mailers/waiting_list_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# app/mailers/waiting_list_mailer.rb
class WaitingListMailer < ApplicationMailer
default from: '[email protected]'

def daily_report(email)
@waiting_list = WaitingList.all
@total_count = @waiting_list.count
@today_count = @waiting_list.where('created_at >= ?', Time.zone.now.beginning_of_day).count
@url = 'https://linkarooie.com'

mail(to: email, subject: 'Daily Waiting List Report - Linkarooie')
end
end
63 changes: 63 additions & 0 deletions app/views/waiting_list_mailer/daily_report.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<!-- app/views/waiting_list_mailer/daily_report.html.erb -->
<!DOCTYPE html>
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
<style>
body {
font-family: Arial, sans-serif;
line-height: 1.6;
color: #333;
}
.container {
max-width: 600px;
margin: 0 auto;
padding: 20px;
}
h1 {
color: #4a5568;
}
.stats {
background-color: #f0fff4;
border: 1px solid #9ae6b4;
border-radius: 5px;
padding: 15px;
margin-bottom: 20px;
}
ul {
list-style-type: none;
padding-left: 0;
}
li {
margin-bottom: 10px;
}
.footer {
margin-top: 30px;
font-size: 0.9em;
color: #718096;
}
</style>
</head>
<body>
<div class="container">
<h1>Daily Waiting List Report - Linkarooie</h1>

<div class="stats">
<p><strong>Total subscribers:</strong> <%= @total_count %></p>
<p><strong>New subscribers today:</strong> <%= @today_count %></p>
</div>

<h2>All Subscribers:</h2>
<ul>
<% @waiting_list.each do |subscriber| %>
<li><%= subscriber.email %> (joined: <%= subscriber.created_at.strftime('%B %d, %Y') %>)</li>
<% end %>
</ul>

<div class="footer">
<p>Visit Linkarooie at: <a href="<%= @url %>"><%= @url %></a></p>
<p>This is an automated message from Linkarooie. Please do not reply to this email.</p>
</div>
</div>
</body>
</html>
4 changes: 4 additions & 0 deletions config/sidekiq_scheduler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ aggregate_metrics:
backup_database:
cron: '0 2 * * *' # Runs daily at 2 AM
class: BackupDatabaseJob

send_waiting_list_report:
cron: '0 3 * * *' # Runs daily at 3 AM
class: SendWaitingListReportJob

0 comments on commit 2e15cb1

Please sign in to comment.