Reputation: 31950
I've successfully deployed a Cron job to App Engine, for a Java application using the App Engine Standard environment. It deploys successfully, however the cron job fails, and when I check the log, it isn't calling the correct service:
"GET /my-app HTTP/1.1" 404 - - "AppEngine-Google; (+http://code.google.com/appengine)"
"my-project.appspot.com"
Other cron jobs that are working look like this (note that the last part shows the service name and not just the project name):
"GET /my-app HTTP/1.1" 404 - - "AppEngine-Google; (+http://code.google.com/appengine)"
"my-service.my-project.appspot.com"
Here is my cron.xml:
<?xml version="1.0" encoding="UTF-8"?>
<cronentries>
<cron>
<url>/my-app</url>
<description>my app</description>
<schedule>every 1 minutes from 00:00 to 23:00</schedule>
<timezone>Europe/Paris</timezone>
</cron>
</cronentries>
And my web.xml:
<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<servlet>
<servlet-name>my-app</servlet-name>
<servlet-class>com.my.package.MyApp</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>my-app</servlet-name>
<url-pattern>my-app</url-pattern>
</servlet-mapping>
</web-app>
And my servlet definition (this is a Cloud Endpoint app, which uses a Java servlet):
@WebServlet(
name = "my-app",
urlPatterns = {"/my-app"}
)
public class MyApp extends HttpServlet {
...
And my appengine-web.xml:
<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
....
<application>my-project</application>
<service>my-app</service>
....
</appengine-web-app>
Why isn't the cron job calling the service? The service is also correctly deployed.
Upvotes: 1
Views: 724
Reputation: 5539
The following example creates a basic cron job that runs daily:
<?xml version="1.0" encoding="UTF-8"?>
<cronentries>
<cron>
<url>/tasks/summary</url>
<target>beta</target>
<description>daily summary job</description>
<schedule>every 24 hours</schedule>
</cron>
</cronentries>
The target specification is optional and is the name of a service/version. If present, the target is prepended to your app's hostname, causing the job to be routed to that service/version. If no target is specified, the job will run in the versions of the default service that are configured for traffic.
I think this is what is happening in your case. Since you have not specified the target
, the cron job is hitting the /my-app route on default service. Mention the service name in the target.
Upvotes: 1
Reputation: 31950
My cron.xml needed a <target>
that matches the <service>
in my appengine-web.xml
cron.xml
<?xml version="1.0" encoding="UTF-8"?>
<cronentries>
<cron>
<url>/my-app</url>
<!-- <target> required -->
<target>my-app</target>
<description>my app</description>
<schedule>every 1 minutes from 00:00 to 23:00</schedule>
<timezone>Europe/Paris</timezone>
</cron>
</cronentries>
appengine-web.xml
<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
....
<application>my-project</application>
<!-- cron <target> must match service -->
<service>my-app</service>
....
</appengine-web-app>
Upvotes: 2