How do I use modules in Google App Engine and add a target to them using Task Queue (Java)?

I have a task that is longer than 10 minutes in the task queue. Looking through various docs, I found that with modules I can start an instance that would handle a long running task, but preferably even that should be done using a task queue. I've used backends, but they are deprecated.

My question is, how can I expose Modules to my existing App Engine project and how can I use them to perform long running tasks?

Below is the code snippet:

Queue queue = QueueFactory.getQueue("myqueue");
TaskOptions task = TaskOptions.Builder.withUrl("/submitworker").method(Method.POST);
queue.add(task);

      

What changes should I make to the above code to add a long running task using a module? ["Submitworker" is the servlet that is the longest running task)

I referenced this link, but I can't get around the third step:
3. Add the service declaration elements to the appengine-application.xml file.

Also, even if I successfully add a module to my project, how do I set up the target module using Task Queue?

I went through this question, but this is a python implementation, my implementation in Java.

I am looking for a step by step process on how to use "Target" in modules and how to use it when adding to a task queue.

Even if I add the target portion of a long-term unit to the task queue, will it still stop after 10 minutes, or will the task finish executing even if the task in the task queue expires?

Please suggest.

+2


source to share


2 answers


Modules and Services are one and the same, they look like old backends (which still work, but are outdated).

There are two main ways modules work:

  • Create EAR and deploy
  • Deploy services independently as WAR files (which you probably now do with the default module)

The second option is probably easier because it's just a matter of modifying your app-web.xml. You can have a repo or branch per module, or just a build process that modifies a module you have configured.

Now, your app-web.xml probably has something like this:



<application>@appId@</application>
<version>@appVersion@</version>    
<module>default</module>   

      

change it to something like this

<application>@appId@</application>
<version>@appVersion@</version>    
<module>long-running-service</module>
<instance-class>B1</instance-class>
<manual-scaling>
    <instances>1</instances>
</manual-scaling>

      

You set up the queue yourself to target a specific module in queue.xml

See here .

0


source


Disclaimer: The answer is purely based on the docs (I'm actually using python - the same concepts, but different configs).

To make a service / module solve a long running task, you have to configure it for basic or manual scaling. From Scaling Types and Instance Classes (row Deadline

in table):

  • in the column Manual scaling

    :

Queries can run indefinitely. The screen is manually scaled. process / _ah / run and execute a program or script for many hours without returning an HTTP response code. Tasks can run up to 24 hours.

  • in the column Basic scaling

    :

Same as manual scaling.

Module scaling configurations performed through the appropriate file appengine-web.xml

are described in Scaling elements :

  • <manual-scaling>

    :

Additionally. The element allows manual scaling for the module and sets the number of instances for the module.

  • <basic-scaling>

    :


Additionally. The element sets the number of instances for the module.

As for the actual conversion to modules, add the manual you pointed to with Config files (including example ) and appengine-web.xml

Syntax
(see module

and service

configs).

Oh appengine-application.xml

, from the config files :

The META-INF directory has two configuration files: appengine-application.xml

and application.xml

. The file appengine-application.xml

contains general information used by App Engine when your application is deployed ...

...

Note that although every file appengine-web.xml

must contain a Tag <application>

, the name you supply there is ignored. The application name is taken from the tag <application>

in appengine-application.xml

.

To route a specific queue to a specific service / module, you use a queue.xml

. From Syntax :

  • <target>

    (push queues):

Additionally. A string representing the module / version, external version or backend on which all tasks assigned to this queue are executed.

The string is appended to your application's domain name when building an HTTP request for a task. For example, if your application id is my-app and you set the target to my-version.my-service , the host url will be set to my-version.my-service.my-app.appspot.com .

If no target is specified, the tasks are called in the same version of the application in which they were queued. So, if you are tasks from the default version of the application without specifying the target in the queue, the task is launched in the default version of the application. Note that if the default version of the application changes between the time that the task is queued and the time it runs, then the task will run in the new version by default.

If you use modules in conjunction with a submit file , your HTTP request task might be intercepted and redirected to another module.

0


source







All Articles