Question

I have GAE application. I have Emails to the NoSQL and their refresh tokens of google Drive. I have Cron job which fires Push queue for each PDF in order to download this.

No I want to send email to each user about their PDF data.

I cant send email for each document (for example if user test@gmail.com have 10 pdf document), I can send 10 email to this mail - each pdf task sends each mail.
BUT how to collect users data and send together?

Each task work on each PDF. I should collect each user data together. and I shoud send one email about all the document (in my example, one email want to contain 10 pdf document data).

I have one idea - to save that data in Datastore, and next day another , another Cron job will collect data from DB and send mails. is this way good?

Was it helpful?

Solution

Yes, collect the data in datastore, and send once a day. A typical model might be (in python):

class DigestEmail(db.Model):
  recipient = db.StringProperty()
  pdf_id = db.StringProperty()
  sent = db.BooleanProperty(default=False)

Then when you need to send an email from your taskqueue, create a DigestEmail entity. Then, once a day (or whatever), query your DigestEmail entities where sent = False, ordered by recipient, like this:

query = DigestEmail.gql('WHERE sent = False ORDER BY recipient')

Then iterate through your query results and group together by recipient. Send the email, and set the sent property to True to prevent it being sent again. (Alternatively, delete the entities altogether).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top