Using GAE Cron to send mails daily

170 views
Skip to first unread message

許吉宏

unread,
Aug 10, 2014, 11:27:36 PM8/10/14
to google-a...@googlegroups.com
Hi There,
 Has anyone ever used GAE Cron to send mails daily ? I used GAE Mail API (CreateAuthorizedService('gmail', 'v1') ) to send a mail by Cron daily.
Unfortunately , I never got one but Corn logs said it was successfully. 
I tested copied all codes to normal .py file and executed it , it worked perfecly and I could get the mail . 
Does anyone know where is wrong with GAE Cron ? Thank you .


Regards,
Aoyii

Vinny P

unread,
Aug 11, 2014, 1:44:46 PM8/11/14
to google-a...@googlegroups.com
On Sun, Aug 10, 2014 at 10:27 PM, 許吉宏 <2pytho...@gmail.com> wrote:
 Has anyone ever used GAE Cron to send mails daily ? I used GAE Mail API (CreateAuthorizedService('gmail', 'v1') ) to send a mail by Cron daily.
Unfortunately , I never got one but Corn logs said it was successfully.  
Does anyone know where is wrong with GAE Cron ?
 
 
You should be able to send emails via cron-initiated requests. Did you check the application logs (under logging) and the cron success status (under the Cron tab) for errors?
 
 
On Sun, Aug 10, 2014 at 10:27 PM, 許吉宏 <2pytho...@gmail.com> wrote:
I used GAE Mail API (CreateAuthorizedService('gmail', 'v1') )
 
 
-----------------
-Vinny P
Technology & Media Consultant
Chicago, IL

App Engine Code Samples: http://www.learntogoogleit.com
 

許吉宏

unread,
Aug 11, 2014, 9:57:22 PM8/11/14
to google-a...@googlegroups.com
Hi Vinny,
   Yes , I'm using Gmail API and it works if I executes it manually . Moreover , on the Cron tab , it says running the job successfully . 
But on the application logs I got the information below . Any suggestion to solve it ? Thank you .

"This request caused a new process to be started for your application, and thus caused your application code to be loaded for the first time. This request may thus take longer and use more CPU than a typical request for your application" 

BR,
Aoyii

Vinny P於 2014年8月12日星期二UTC+8上午1時44分46秒寫道:

PK

unread,
Aug 11, 2014, 11:41:24 PM8/11/14
to google-a...@googlegroups.com
I am not sure what your problem is but I send e-mails initiated by cron requests all the time. 

PK
--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-appengi...@googlegroups.com.
To post to this group, send email to google-a...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-appengine.
For more options, visit https://groups.google.com/d/optout.

Alejandro Gonzalez

unread,
Aug 12, 2014, 3:24:12 AM8/12/14
to google-a...@googlegroups.com
"This request caused a new process to be started for your application, and thus caused your application code to be loaded for the first time. This request may thus take longer and use more CPU than a typical request for your application" 


Loading request should be executed normally, but they take more time to execute becouse GAE needs to start an instance to execute it, it the request plus the start process is less than 60sec. If its exceeds the 60 secs you should see a DeadlineExeededException

You can try a couple of things:

1 - Start a cron to make a request that rise the instance 1 min before launching the mail cron, so when the mail cron is executed the instance is up.

2 - Use a backend or Module (https://developers.google.com/appengine/docs/java/modules/?hl=es) to handle the mail cron

3 - If you don't need Gmail API try using the more simple Appengine built in mail API ( https://developers.google.com/appengine/docs/python/mail/)


cheers!




--

Vinny P

unread,
Aug 12, 2014, 8:12:13 AM8/12/14
to google-a...@googlegroups.com
On Mon, Aug 11, 2014 at 8:57 PM, 許吉宏 <2pytho...@gmail.com> wrote:
  I'm using Gmail API and it works if I executes it manually


Instead of using the Gmail API to send email, can you temporarily try using the built-in mail function to send mail? https://developers.google.com/appengine/docs/python/mail/ 




On Mon, Aug 11, 2014 at 8:57 PM, 許吉宏 <2pytho...@gmail.com> wrote:
But on the application logs I got the information below . Any suggestion to solve it ? Thank you .

"This request caused a new process to be started for your application, and thus caused your application code to be loaded for the first time. This request may thus take longer and use more CPU than a typical request for your application" 


That's OK, that message is normal. Do you see any error signs in the log (non-200 status code, a red icon next to a request log, etc)?
 

許吉宏

unread,
Aug 27, 2014, 1:29:06 AM8/27/14
to google-a...@googlegroups.com
Hi Vinny P,
  Followed your suggestion , I used built-in mail function to send mail by cron successfully. Do you know why is the reason I can't use Gmail API through Cron?
Any GAE limitation or where is wrong ? Thank you very much .

BR,
Aoyii

Vinny P於 2014年8月12日星期二UTC+8下午8時12分13秒寫道:

許吉宏

unread,
Aug 27, 2014, 1:29:37 AM8/27/14
to google-a...@googlegroups.com
Hi Alejandro Gonzale,
  Followed your suggestion , I used built-in mail function to send mail by cron successfully. Do you know why is the reason I can't use Gmail API through Cron?
Any GAE limitation or where is wrong ? Thank you very much .

BR,
Aoyii

Alejandro Gonzalez於 2014年8月12日星期二UTC+8下午3時24分12秒寫道:

許吉宏

unread,
Sep 1, 2014, 1:53:05 AM9/1/14
to google-a...@googlegroups.com
Hello,
  Anyone can tell me why I can't use Gmail API to send mail by Cron ? Or where I have to do something specifically  ? Thank you .

BR,
Aoyii

許吉宏於 2014年8月11日星期一UTC+8上午11時27分36秒寫道:

Vinny P

unread,
Sep 1, 2014, 1:43:33 PM9/1/14
to google-a...@googlegroups.com
On Wed, Aug 27, 2014 at 12:29 AM, 許吉宏 <2pytho...@gmail.com> wrote:
Hi Vinny P,
  Followed your suggestion , I used built-in mail function to send mail by cron successfully. Do you know why is the reason I can't use Gmail API through Cron? Any GAE limitation or where is wrong ? Thank you very much .


That's the thing: there isn't any GAE limitation. You should be able to use the Gmail API from cron requests just like any other Google API service.

What I would try is this: try accessing any other Google API from a cron request and see if it succeeds. For example, try using the URL Shortener API ( https://developers.google.com/url-shortener/v1/getting_started#shorten ) and see if any problems pop up. Also, try using your cron request to spawn off a task queue requestdelay the task by 30 seconds by using the countdown argument, and running your Gmail code within the task queue request. 
Reply all
Reply to author
Forward
0 new messages