Problem running a cron job

59 views
Skip to first unread message

Ken Bowen

unread,
Jun 29, 2015, 12:02:20 AM6/29/15
to google-a...@googlegroups.com

I have a simple test cron job which does not succeed in running on GAE.  The target url runs correctly when invoked from a browser (when I’m logged in as admin),  but cron is not successfully running the job.  The GAE Cron Jobs page shows:

    /admin/cron/crontest1    every 2 hours (America/New_York) 
    Initial simple test            2015/06/28 23:18:03 2 secs late Failed

Here’s the cron.xml:
<?xml version="1.0" encoding="UTF-8"?>
<cronentries>
<cron>
    <description>Initial simple test</description>
    <timezone>America/New_York</timezone>
    <url>/admin/cron/crontest1/</url>
    <schedule>every 2 hours</schedule>
</cron>
</cronentries>

In web.xml, the <url-pattern>/admin/*</url-pattern> gets the   <security-constraint>:
<auth-constraint>
             <role-name>admin</role-name>
        </auth-constraint>

The target url /admin/cron/crontest1/ assembles a very simple jsp page equivalent to:
<head>
    <script type='text/javascript' src='/admin/cron/crontest1/crontest1.js'></script>
    <script>
$(document).ready(function() {
   crontest1init();
});
    </script>
</head>
<body> 
<h1>CronTest1</h1>  
</body> 

where crontest1.js is just:

function crontest1init()
{
AdminIntf.crontest1();
}

And AdminIntf.crontest1() is just a DWR (Direct Web Remoting) call to this:

public static void crontest1(){
    final DateTimeFormatter fmt = Constants.YMDHMS_DATETIME_FORMATTER;
        String now = fmt.print(System.currentTimeMillis());
        logger.warn("############## crontest1() ############: " + now);
}

When I am logged in as admin and issue the url


the result is a page showing

CronTest1

and the logs show:

……/dwr/call/plaincall/AdminIntf.crontest1.dwr 200 …blah,blah
I 2015-06-28 21:10:18.026 org.directwebremoting.util.CommonsLoggingOutput info: Exec: AdminIntf.crontest1()
W 2015-06-28 21:10:18.064 com.strongbrain.admin.AdminIntf crontest1: ############## crontest1() ############: 2015-06-29 03:10:18 UTC

The url action returns 200, but, as noted at top, cron doesn’t successfully run this.  Clearly I’m missing something essential, but I can’t see what.
Any help will definitely be appreciated.
Thanks in advance,
Ken Bowen

Patrice (Cloud Platform Support)

unread,
Jun 29, 2015, 1:41:03 PM6/29/15
to google-a...@googlegroups.com, k...@form-runner.com
Hey Ken,

I'm a bit unclear on your issue, so if you could clarify, it would be helpful.

You have a cronJob on the /admin/cron/crontest1 URL that creates a js and displays it. When you hit the url yourself, it goes through... but when the job autoruns, it fails... right?

If this is the behavior you're experiencing, I'd say it's to be expected... how would a scheduled cron job running on the backend display anything?

Let me know if I'm the one not understanding your issue properly here.

Cheers!

Ken Bowen

unread,
Jun 29, 2015, 6:56:06 PM6/29/15
to google-a...@googlegroups.com
Hey Patrice,

It’s my mistake. All I really wanted to do was execute the java method
public static void crontest1(){
final DateTimeFormatter fmt = Constants.YMDHMS_DATETIME_FORMATTER;
String now = fmt.print(System.currentTimeMillis());
logger.warn("############## crontest1() ############: " + now);
}

The jsp/js was just going to be a stepping stone to this, but now I understand the fact that cron isn’t going to execute that jsp “headless”.

o am I correct that the right way to do this is to write a simple servlet, something like this:

public class CronTest1Servlet extends LoggedHttpServlet {
private static Logger logger = Logger.getLogger(CronTest1Servlet.class.getName());
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{ final DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss z");
String now = fmt.print(System.currentTimeMillis());
logger.warn("############## CronTest1Servlet ############: " + now); }
}

Thanks much,
—Ken
> --
> You received this message because you are subscribed to a topic in the Google Groups "Google App Engine" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-appengine/3OjCkOL2jhI/unsubscribe.
> To unsubscribe from this group and all its topics, 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.
> To view this discussion on the web visit https://groups.google.com/d/msgid/google-appengine/e49bc100-aeda-475c-94d4-0dc9b3ef94b8%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Patrice (Cloud Platform Support)

unread,
Jun 30, 2015, 9:52:24 AM6/30/15
to google-a...@googlegroups.com, k...@form-runner.com
Hi Ken!

If you want to call that method and log the time when you call this? yes definitely, this is what you want, and then you just hit that servlet whenever you want that logged.

Cheers!
> To unsubscribe from this group and all its topics, send an email to google-appengine+unsubscribe@googlegroups.com.
> To post to this group, send email to google-appengine@googlegroups.com.

Ken Bowen

unread,
Jun 30, 2015, 1:57:50 PM6/30/15
to google-a...@googlegroups.com
Patrice,

Thanks,

Ken
> > To unsubscribe from this group and all its topics, send an email to google-appengi...@googlegroups.com.
> > To post to this group, send email to google-a...@googlegroups.com.
> --
> You received this message because you are subscribed to a topic in the Google Groups "Google App Engine" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-appengine/3OjCkOL2jhI/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to google-appengi...@googlegroups.com.
> To post to this group, send email to google-a...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/google-appengine/c2d8444c-84a3-4693-979c-5b30fdca4cf7%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages