Clark
Clark

Reputation: 2678

Google Cloud Platform - Scheduler?

I have a real time Node application which I plan to run on Google Cloud. It is real time because the sever must always be in sync with Firebase. For example, to process Search functionality etc. So I will have this constantly ticking thing, which just sits waiting for Events to happen.

One of the core parts of the application is the concept that Events (Date and Time) can be created.

What I need, is essentially a Black Box. I want to say "Tell me at 23rd of December at 8pm about this Event". Kind of like a Mega long callback or something I can subscribe to.

I know that cron is available, but that isn't quite what I want. A cron has no real business in an real time application and doesn't feel right. My Application should adapt to Events. I don't want a machine gun firing once a minute 24/7 especially when no changes have been made to the system. I need to ditch the time based polling idea.

I believe what I really need is a Scheduler which appears to be like a Cron, but more "Real time".

This led me Microsoft Azure which has a Scheduler

I think that might be exactly what I need. If so, is there a Google Cloud equivalent that I may be missing in the Docs?

Upvotes: 2

Views: 2356

Answers (2)

In your case, Google Cloud Functions - and more generally Functions As A Service / Serverless - seem like the best fit for running event driven pieces of code. On GCP, it basically consists into uploading to a bucket a nodejs module, with your logic embedded into an exported function.

From the docs :

/**
 * Cloud Function.
 *
 * @param {object} event The Cloud Functions event.
 * @param {function} callback The callback function.
 */
exports.helloWorld = function helloWorld (event, callback) {
  console.log(`My Cloud Function: ${event.data.message}`);
  callback();
};

You can read more about here.

Upvotes: 0

Dan Cornilescu
Dan Cornilescu

Reputation: 39834

The GAE flexible environment offers a similar cron service.

From Scheduling Jobs with cron.yaml:

The App Engine Cron Service allows you to configure regularly scheduled tasks that operate at defined times or regular intervals. These tasks are commonly known as cron jobs. These cron jobs are automatically triggered by the App Engine Cron Service. For instance, you might use this to send out a report email on a daily basis, to update some cached data every 10 minutes, or to update some summary information once an hour.

A cron job will invoke a URL, using an HTTP GET request, at a given time of day. An HTTP request invoked by cron can run for up to 60 minutes, but is subject to the same limits as other HTTP requests.

From About cron.yaml

The following is an example cron.yaml file:

cron:
- description: daily summary job
  url: /tasks/summary
  schedule: every 24 hours
- description: monday morning mailout
  url: /mail/weekly
  schedule: every monday 09:00
  timezone: Australia/NSW
- description: new daily summary job
  url: /tasks/summary
  schedule: every 24 hours
  target: beta

So all you need to do is to configure such cron jobs (triggers) for whatever actions you need and add handlers for the respective URLs performing those actions.

From The schedule format:

The following are examples of schedules:

every 12 hours
every 5 minutes from 10:00 to 14:00
every day 00:00
every monday 09:00
2nd,third mon,wed,thu of march 17:00
1st monday of sep,oct,nov 17:00
1 of jan,april,july,oct 00:00

Note: it's not yet possible to schedule the cron jobs programmatically, but there's a feature request for it.

The cron.yaml for the particular example mentioned in the question:

cron:
- description: trigger the Dec 23rd event
  url: /events/12.23
  schedule: 23 of dec 20:00

To deploy the cron job:

gcloud app deploy cron.yaml

Upvotes: 4

Related Questions