In App Engine, you can use tasks in Push Queues 
<https://cloud.google.com/appengine/docs/standard/java/taskqueue/push/>. 
When you create the task you provide a task option 
<https://cloud.google.com/appengine/docs/standard/java/javadoc/com/google/appengine/api/taskqueue/TaskOptions>,
 
either countdownMillis or etaMillis, that specify the absolute earliest 
time at which the task should run. For pull tasks, no worker can lease a 
task before the time has arrived. The pattern would be to create one push 
task for each notification to be sent and define the countdown or eta 
accordingly, and the payload for email address and related data, and/or one 
for SMS and related data. Once the time has passed, task queue will direct 
the task to your task handler. The task handler will then look into the 
payload and accordingly send notifications using other services. However, 
be aware that you need appropriate task queue configuration for your kind 
of app and work-load, including sudden bursts, and also how to handle 
errors (with-out spamming users in case of errors). There is not guarantee 
that the task will be executed exactly at the specified time (for example, 
if too many tasks are executed for this queue or for the total number of 
instances allowed for the app), execution might happen later. But there is 
a guarantee that the task will run at least once. However, it would make 
sense to track each task back to a certain event or reason in your app. So, 
if a scheduled appointment is changed, the task should be deleted / 
replaced accordingly.

A different approach would be to define pending notifications as Datastore 
entities and trigger their handling by scheduled tasks 
<https://cloud.google.com/appengine/docs/standard/java/config/cron> (cron 
jobs). For example, every 2 minutes (more or less), a cron-job task is 
executed. The cron-job task itself just creates a push task to execute 
immediately. That push task handler will query your Datastore for 
"PendingNotification" entities that have an indexed property "runAfter" 
(datetime), filtered and sorted by this property, where the timestamp is 
already in the past. For each entity in the query, the task handler will 
send the notification accordingly and then delete the entity (so it doesn't 
come up at the next query). That task could do this in batches, for example 
for 10 notifications per execution. If the query would give more results, 
enqueue the same task again. Else just return 200 and quit. Most likely, 
you are already familiar with such patterns if you do batch migrations in 
administrative tasks. If at some point an invoice due date or a scheduled 
service appointment is changed, your app picks the corresponding 
PendingNotification entity and deletes or updates it accordingly.

The key advantages of task queues for apps in App Engine with task queue 
support:

   1. they support namespaces (you probably already use namespaces 
   
<https://cloud.google.com/appengine/docs/standard/java/multitenancy/multitenancy>
 
   for a multi-tenant SaaS app
   2. you can test push queues in the local development server 
   
<https://cloud.google.com/appengine/docs/standard/java/taskqueue/push/using-the-development-server>
   
If you want a similar approach but moving the actual email or SMS sending 
workload out of the App Engine task handlers, you might want to look into Cloud 
Pub/Sub <https://cloud.google.com/pubsub/>, a server-less event-driven 
message system. Although App Engine has a Task Queue REST API, it's 
probably easier in Pub/Sub to integrate with many other clients. Basically, 
clients (like a Cloud Function that will send emails or SMS), subscribes to 
a topic ("notifications"). Once your task handler publishes a message (e.g. 
"send invoice #123 now to u...@example.com"), the client gets the message 
and does its job. So, instead of your final task handler connecting to a 
mail provider or SMS provider, it just publishes a message to a Pub/Sub 
topic and is done, and other parts of your system pick that message and 
continue from there. This combination would reduce instance hours in your 
App Engine app, but then add other costs, e.g. for Pub/Sub messaging, and 
also for Cloud Functions or whatever you want to use to actually send the 
notifications. You probably also need to put a little more thought into 
testing and deployments.

Regards,
Ani

On Friday, May 4, 2018 at 5:11:58 AM UTC+2, Rajesh Gupta wrote:
>
> HI,
>
> We are in erp & field service management SAAS
>
> We use java on appengine.
>
> We need email reminders that needs to be sent our later dates.
>
> For example, for the invoice due date, a reminder has to be sent 1 day 
> early
>
> In field service SAAS, we need to send reminders as SMS 30 min, prior the 
> appointment given to the customer.
>
> What cloud components can be used here  or what should be the design for 
> performing the events at later date&time..   
>
>
> -- 
> Regards,
> Rajesh
> *www.VeersoftSolutions.com <http://www.VeersoftSolutions.com>*
> *www.GainERP.com <https://www.gainerp.com>*
> *ERP & Field Service Management on Google Cloud*
>
>

-- 
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-appengine+unsubscr...@googlegroups.com.
To post to this group, send email to google-appengine@googlegroups.com.
Visit this group at https://groups.google.com/group/google-appengine.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-appengine/72dfaa6b-f85a-42e4-9612-7fb8abc06e7e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to