1

I'm pretty new to coding, so I'm sure I'm missing something simple. I have a cron job set to run my Python Twitter app on Google App Engine every 207 minutes. The script itself runs fine and when I make changes to cron.yaml, it will run the first time, but won't run any time after that. Looking at the logs, this is the only line that's different between the times it runs and the times it doesn't run:

not running: ms=4 cpu_ms=3 cpm_usd=1.3411e-8 loading_request=0

running: ms=2437 cpu_ms=2610 cpm_usd=1.6462e-7 loading_request=1

enter image description here

I don't know what any of that means.

Here's what cron.yaml looks like:

cron:
- description: Regular Tweets
  url: /
  schedule: every 207 minutes

And here's what app.yaml looks like:

application: thegreenasterisktweeter
version: 10
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: /favicon\.ico
  static_files: favicon.ico
  upload: favicon\.ico
- url: /.*
  script: main.app
libraries:
- name: ssl
  version: latest
- name: lxml
  version: latest
env_variables:
  GAE_USE_SOCKETS_HTTPLIB : '53778008'

and here's the handler in my script screenshot

Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97
  • Post a screenshot of both logs + code of cron handler (main.py) – MeLight Jul 31 '16 at 12:29
  • Edited just now with links to those screenshots. – Steve Beaudry Aug 01 '16 at 17:01
  • I missed that in the first read of your question: you're getting logs for the call both times - which means both times it runs. The cron job's role is to open the handler URL. If you get the logs - it happened. – MeLight Aug 01 '16 at 17:30
  • The cron servicedoes nothing more than issuing `GET` requests for the specified URL at the specified time(s). Everything else is basically your app serving those `GET` requests. Leaving the timing aside for now you can check your app's serving those requests simply by issuing the requests manually. And the timing can be easily checked by the logs (each request is logged) - which appeared to have happened correctly, as @MeLight mentioned. – Dan Cornilescu Aug 02 '16 at 00:23
  • BTW, please don't post text/code as images, instead copy-paste it in your POST and format it accordingly. – Dan Cornilescu Aug 02 '16 at 00:27
  • Side note: you probably want to use a more specific URL for cron (you don't want every bot out there triggering your app execution). You should probably take a look at this as well: http://stackoverflow.com/questions/14193816/google-app-engine-security-of-cron-jobs – Dan Cornilescu Aug 02 '16 at 00:29
  • Okay, well, the script still isn't tweeting the second or subsequent times that it's called through cron even though it'll do it just fine if I call it manually. Any idea why this might be the case? – Steve Beaudry Aug 02 '16 at 12:55
  • Judging by the logs, the cron job is successfully running as mentioned in a previous comment. The measure of success for the cron job is the handler you've deployed receiving the regular `GET` request prescribed. Following this, the handler is responsible for then issuing a proper request to the relevant Twitter API. From the code sample provided, this handler is simply writing the tweet to a response, not a Twitter API. Is the actual code of your cron handler or have you changed it for this post? – Nicholas Aug 03 '16 at 22:01
  • I didn't change it for the post, no. What am I missing? – Steve Beaudry Aug 05 '16 at 01:42
  • Nevermind, I see what you're saying. I didn't change the code, but that is just a snippet to show something on the page where it's hosted. The rest of the code properly builds and sends a tweet using Tweepy. – Steve Beaudry Aug 05 '16 at 13:04

0 Answers0