Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

send a Year Three email #3510

Closed
wants to merge 12 commits into from
Closed

send a Year Three email #3510

wants to merge 12 commits into from

Conversation

chadwhitacre
Copy link
Contributor

Picking up from #3508.

@chadwhitacre
Copy link
Contributor Author

I'm planning to write a script to queue this locally, with a production Mandrill key in local.env for sending.

I tried a bit to find an old gratipocalypse branch that I thought might
have the script on it that I used for the Gratipocalypse email, but
alackaday.
But not in text/plain. :P
Takes a limit and returns the number sent. This commit may be worth
cherry-picking and testing.
So we can do `from gratipay.main import db` in scripts.
@chadwhitacre
Copy link
Contributor Author

Alright, how's this?

screen shot 2015-06-01 at 6 02 14 pm

@chadwhitacre
Copy link
Contributor Author

Subject: Gratipay, Year Three

@chadwhitacre
Copy link
Contributor Author

screen shot 2015-06-01 at 6 07 23 pm

@chadwhitacre
Copy link
Contributor Author

Okay! Ready?

@chadwhitacre
Copy link
Contributor Author

I'm downloading a backup. I'll use that to populate the participants list, and I'll put a production Mandrill key in local.env for sending. After we're done I'll remove the production Mandrill key from local.env.

@chadwhitacre
Copy link
Contributor Author

Backup loaded.

=> select count(*) from participants where email_address is not null 
and is_suspicious is not true and is_closed is not true and claimed_time is not null;
┌───────┐
│ count │
├───────┤
│  2812 │
└───────┘
(1 row)

@chadwhitacre
Copy link
Contributor Author

Matches production. As I recall we mailed Gratipocalypse to ~2600 folks. We've picked up 200 email addresses since then, I suppose?

@chadwhitacre
Copy link
Contributor Author

Indeed! :)

=> select count(*) from emails where verified and verification_end > 'May 7, 2015';
┌───────┐
│ count │
├───────┤
│   239 │
└───────┘
(1 row)

@chadwhitacre
Copy link
Contributor Author

Alright, list of participants ready to go in local db ...

@chadwhitacre
Copy link
Contributor Author

Okay, my local.env is pointing to the backup database and production Mandrill. Code is at 0c841fd. Here's my command line:

[gratipay] $ run_dammit defaults.env local.env -c ./env/bin/python bin/send-year-three.py

Here's run_dammit.

@chadwhitacre
Copy link
Contributor Author

I expect the next run to output 2812 and then fail on the first assert.

@chadwhitacre
Copy link
Contributor Author

For 2,812 emails at 1 per second, it's going to take 47 minutes to send all of these out. It'd be nice if that went faster. What are our rate limits at Mandrill?

@chadwhitacre
Copy link
Contributor Author

Our hourly limit is 6,561.

@chadwhitacre
Copy link
Contributor Author

What if I use threaded_map here?

@chadwhitacre
Copy link
Contributor Author

Hmm ... would have to unroll/monkey around with dequeue_emails for that. Easier to just whack the sleep. What are the implications of that?

@chadwhitacre
Copy link
Contributor Author

Why was it added in the first place?

@chadwhitacre
Copy link
Contributor Author

Yeah, I'm not finding an explanation for why we implemented throttling the way we did. I'm going to whack the sleep for this mail run.

@chadwhitacre
Copy link
Contributor Author

Still might take a second per API call. We'll see. :)

@chadwhitacre
Copy link
Contributor Author

The email queue doesn't look thread-safe to me, anyway.

@chadwhitacre
Copy link
Contributor Author

So far so good ...

[gratipay] $ run_dammit defaults.env local.env -c ./env/bin/python bin/send-year-three.py 
2812
[snip]
Traceback (most recent call last):
  File "bin/send-year-three.py", line 37, in <module>
    assert len(participants) == 1
AssertionError
[gratipay] $

@chadwhitacre
Copy link
Contributor Author

diff --git a/gratipay/models/participant.py b/gratipay/models/participant.py
index a8ae2f9..b20c04d 100644
--- a/gratipay/models/participant.py
+++ b/gratipay/models/participant.py
@@ -688,7 +688,7 @@ class Participant(Model, MixinTeam):
                 p = cls.from_id(msg.participant)
                 r = p.send_email(msg.spt_name, **pickle.loads(msg.context))
                 cls.db.run("DELETE FROM email_queue WHERE id = %s", (msg.id,))
-                if r == 1:
+                if 0 and r == 1:
                     sleep(1)
                 nsent += r
         return nsent

@chadwhitacre
Copy link
Contributor Author

diff --git a/bin/send-year-three.py b/bin/send-year-three.py
index 698bb2b..1bd2363 100644
--- a/bin/send-year-three.py
+++ b/bin/send-year-three.py
@@ -34,8 +34,8 @@ print([(p.username, p.email_address) for p in random.sample(participants, 5 if N
 # ----------------------------------------- SAFETY BELT ----------------------------------------- #
 # ----------------------------------------- SAFETY BELT ----------------------------------------- #
 # ----------------------------------------- SAFETY BELT ----------------------------------------- #
-assert len(participants) == 1
-assert participants[0].email_address == '[email protected]'
+#assert len(participants) == 1
+#assert participants[0].email_address == '[email protected]'
 # ----------------------------------------- SAFETY BELT ----------------------------------------- #
 # ----------------------------------------- SAFETY BELT ----------------------------------------- #
 # ----------------------------------------- SAFETY BELT ----------------------------------------- #
diff --git a/gratipay/models/participant.py b/gratipay/models/participant.py
index a8ae2f9..b20c04d 100644
--- a/gratipay/models/participant.py
+++ b/gratipay/models/participant.py
@@ -688,7 +688,7 @@ class Participant(Model, MixinTeam):
                 p = cls.from_id(msg.participant)
                 r = p.send_email(msg.spt_name, **pickle.loads(msg.context))
                 cls.db.run("DELETE FROM email_queue WHERE id = %s", (msg.id,))
-                if r == 1:
+                if 0 and r == 1:
                     sleep(1)
                 nsent += r
         return nsent

@chadwhitacre
Copy link
Contributor Author

Script started!

[gratipay] $ run_dammit defaults.env local.env -c ./env/bin/python bin/send-year-three.py > send-year-three.log

@chadwhitacre
Copy link
Contributor Author

Queueing ...

@chadwhitacre
Copy link
Contributor Author

Wish I turned off stdio buffering. :-/

@chadwhitacre
Copy link
Contributor Author

Ack. I killed the script because I thought for a second that I had loaded up the production email queue, in which case the dequeue_emails in the script would compete with the one in the thread in production. I've confirmed that I loaded up my local queue.

@chadwhitacre
Copy link
Contributor Author

=# select count(*) from email_queue;                                                              
┌───────┐
│ count │
├───────┤
│  2628 │
└───────┘
(1 row)

@chadwhitacre
Copy link
Contributor Author

Rerunning as ...

#!/usr/bin/env python
"""This is a one-off script to send emails for #3510.
"""
from __future__ import print_function

import sys
class DevNull:
    def write(*a): pass
    def flush(*a): pass
sys.stdout = DevNull()
from gratipay.main import Participant
sys.stdout = sys.__stdout__


print("Flushing email queue ...")
nsent = Participant.dequeue_emails()
print("Sent {} email{}.".format(nsent, '' if nsent == 1 else 's'))

@chadwhitacre
Copy link
Contributor Author

$ watch -n1 "psql gratipay-bak -c 'select count(*) from email_queue;'"

@chadwhitacre
Copy link
Contributor Author

Definitely going faster than one per second. :)

@chadwhitacre
Copy link
Contributor Author

Okay!

Emails 2315, Supper 1 :]

bbiab ...

@chadwhitacre
Copy link
Contributor Author

Every 1.0s: psql gratipay-bak -c 'select count(*) from email_queue;'                  Mon Jun  1 20:05:51 2015

 count
-------
     0
(1 row)

@chadwhitacre
Copy link
Contributor Author

💃

@chadwhitacre chadwhitacre deleted the year-three branch June 2, 2015 00:08
@chadwhitacre
Copy link
Contributor Author

Production Mandrill key removed from my local.env. :)

@chadwhitacre
Copy link
Contributor Author

If I had it to do over again I would've emphasized the changes more: we're not "back to processing" for most users. :-(

@chadwhitacre
Copy link
Contributor Author

Here is the only record we have of the Gratipocalypse mailing: #3385 (comment).

@mattbk
Copy link
Contributor

mattbk commented Jul 23, 2015

If I had it to do over again I would've emphasized the changes more: we're not "back to processing" for most users. :-(

I'd have to agree that there seem to be a fair number of people who didn't catch the team approval requirement. Some have emailed support since then, some (as shown in these recent tweets) don't realize they aren't receiving anymore.

@mattbk mattbk mentioned this pull request Jul 23, 2015
1 task
@chadwhitacre
Copy link
Contributor Author

:-/

Let's try to do a better job of communicating with #3539.

P.S. Thanks for rep'ing on Twitter.

mattbk referenced this pull request in RunestoneInteractive/RunestoneServer Aug 19, 2015
@chadwhitacre chadwhitacre mentioned this pull request Dec 13, 2016
21 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants