mirror of
https://github.com/neocities/neocities.git
synced 2025-05-21 19:59:36 +02:00
pace out the email sending
This commit is contained in:
parent
da4c51e1ef
commit
cff1c3a20b
3 changed files with 10 additions and 8 deletions
|
@ -25,6 +25,7 @@ post '/admin/email' do
|
||||||
day = 0
|
day = 0
|
||||||
|
|
||||||
until sites.empty?
|
until sites.empty?
|
||||||
|
seconds = 0.0
|
||||||
queued_sites = []
|
queued_sites = []
|
||||||
Site::EMAIL_BLAST_MAXIMUM_PER_DAY.times {
|
Site::EMAIL_BLAST_MAXIMUM_PER_DAY.times {
|
||||||
break if sites.empty?
|
break if sites.empty?
|
||||||
|
@ -32,12 +33,13 @@ post '/admin/email' do
|
||||||
}
|
}
|
||||||
|
|
||||||
queued_sites.each do |site|
|
queued_sites.each do |site|
|
||||||
EmailWorker.perform_at(day.days.from_now, {
|
EmailWorker.perform_at((day.days.from_now + seconds), {
|
||||||
from: 'noreply@neocities.org',
|
from: 'Kyle from Neocities <kyle@neocities.org>',
|
||||||
to: site.email,
|
to: site.email,
|
||||||
subject: params[:subject],
|
subject: params[:subject],
|
||||||
body: params[:body]
|
body: params[:body]
|
||||||
})
|
})
|
||||||
|
seconds += 0.5
|
||||||
end
|
end
|
||||||
|
|
||||||
day += 1
|
day += 1
|
||||||
|
|
|
@ -154,7 +154,7 @@ class Site < Sequel::Model
|
||||||
if ENV['RACK_ENV'] == 'test'
|
if ENV['RACK_ENV'] == 'test'
|
||||||
EMAIL_BLAST_MAXIMUM_PER_DAY = 2
|
EMAIL_BLAST_MAXIMUM_PER_DAY = 2
|
||||||
else
|
else
|
||||||
EMAIL_BLAST_MAXIMUM_PER_DAY = 2000
|
EMAIL_BLAST_MAXIMUM_PER_DAY = 1000
|
||||||
end
|
end
|
||||||
|
|
||||||
many_to_many :tags
|
many_to_many :tags
|
||||||
|
|
|
@ -41,16 +41,16 @@ describe 'email blasting' do
|
||||||
|
|
||||||
relevant_jobs.each do |job|
|
relevant_jobs.each do |job|
|
||||||
args = job['args'].first
|
args = job['args'].first
|
||||||
args['from'].must_equal 'noreply@neocities.org'
|
args['from'].must_equal 'Kyle from Neocities <kyle@neocities.org>'
|
||||||
args['subject'].must_equal 'Subject Test'
|
args['subject'].must_equal 'Subject Test'
|
||||||
args['body'].must_equal 'Body Test'
|
args['body'].must_equal 'Body Test'
|
||||||
end
|
end
|
||||||
|
|
||||||
immediate_emails = relevant_jobs.select {|j| j['at'].nil? || j['at'] == Time.now.to_f}
|
relevant_jobs.select {|j| j['at'].nil? || j['at'] == Time.now.to_f}.length.must_equal 1
|
||||||
immediate_emails.length.must_equal Site::EMAIL_BLAST_MAXIMUM_PER_DAY
|
relevant_jobs.select {|j| j['at'] == (Time.now + 0.5).to_f}.length.must_equal 1
|
||||||
|
|
||||||
tomorrows_emails = relevant_jobs.select {|j| j['at'] == (time+1.day.to_i).to_f}
|
relevant_jobs.select {|j| j['at'] == (time+1.day.to_i).to_f}.length.must_equal 1
|
||||||
tomorrows_emails.length.must_equal Site::EMAIL_BLAST_MAXIMUM_PER_DAY
|
relevant_jobs.select {|j| j['at'] == (time+1.day.to_i+0.5).to_f}.length.must_equal 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue