A sidekiq worker sending PDF attachment in emails to clients. The worker runs daily checking if its Sunday then sends weekly report, if today is 15th of month then Bi-monthly report and if last day of month then monthly report. The condition looks something like this:
if sunday?
# send weekly
elsif 15th of month
# send Bi-monthly
elsif last_day_of_month
# send Monthly
end
How to check if its sunday, 15th of month and last day of month ?
Rails has many interesting methods for this kind of date calculations:
today = Date.today
if today.sunday?
# send weekly
elsif today.day == 15
# send bi-monthly
elsif today == today.end_of_month
# send monthly
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With