Scheduling Oracle Cloud Function execution

Lucas Jellema 2

imageFunctions on Oracle Cloud are an important element in any cloud native application architectures. Functions are typically small, well contained and fairly independent pieces of logic to carry out specific tasks. These tasks can be executed upon reception and handling of HTTP requests – a very common use case – or processing of other events. A function can also provide the implementation of a job that should be executed according to a time schedule – and therefore be triggered by time events.

At this point, Oracle Cloud Infrastructure does not provide a native mechanism for defining time based schedules for executing jobs. Scheduling a Function for execution according to a time schedule can be done in a very round about away using a Kubernetes CronJob resource running on OKE (Oracle Kubernetes Engine) as I described in this article earlier this year. This works well – but it is almost silly to start a container (CronJob) in order to invoke a function. Why not do the work the function performs in the container? And of course it requires an OKE cluster to even schedule that CronJob on.

Because functions can be triggered by OCI Cloud Events – such as the creation of a file – we could probably find a way to trigger a function as a result of periodically uploading a file to OCI Object Storage. Again, a fairly convoluted way to trigger a function.

With the recent introduction of API Gateway on Oracle Cloud Infrastructure and its ability to publish Functions on a public endpoint making the function accessible to regular HTTP client, we suddenly have many more options to trigger a Function ojn a time schedule. Perhaps the easiest one if through the use of an IFTTT Applet:

image

In this figure, the IFTTT Applet uses the WebHook Action Service to make a call to the API endpoint on the API Gateway. This endpoint is defined through a Route in the API Gateway Deployment and connects to the Function (in this case silly function Hello). The configuration of the Applet looks like this:

image

The URL used for making the web request is composed of the endpoint of the API Gateway, followed by the path for the API Deployment (/fn) and the path for the route to the Funtion (/hello). For fun I have thrown in an extra path parameter (CheckTime) as well as body to be posted to the function. This information is available in the function – but not used for anything useful because the function does not really do anything useful.

The IFTTT Applet is activated and will cause the function to be invoked every hour, at 15 minutes past the hour. Well, the guarantees are sort of week. The exact time varies a little. And because executing the function most of the times takes a lot time (the function is cold after an hour of inactivity and getting it loaded seems to take longer than IFTTT is prepared to wait, so we see many time outs):

image

The activity of the function is executed regardless of whether IFTTT is still waiting for a response, so these failures are not really a problem. A time scheduled function is called in a fire-and-forget fashion, an that is done perfectly by IFTTT.

The metric monitoring for the API Gateway show the neat periodic activity caused by the IFTTT trigger:

image

And the monitoring for the function executions:

image

Configuring the Function as an API endpoint on API Gateway

The configuration of the function on API Gateway is shown in the following figures:

image

image

Resources

IFTTT documentation Create your own IFTTT Applet

My earlier article on getting started with OCI Functions – My Quick Start with Oracle Functions in Fresh OCI Tenancy – https://technology.amis.nl/2019/12/24/my-quick-start-with-oracle-functions-in-fresh-oci-tenancy/

My first steps with API Gateway on OCI: My first steps with Oracle Cloud API Gateway – the stock response

2 thoughts on “Scheduling Oracle Cloud Function execution

  1. Hi,

    that is a neat way. We stumbled upon the same problem with a k8s cluster being a big overhead, or even a docker container to regularly execute the function it pointless – why not execute the job directly in the container.

    But, I hope Oracle will introduce something natively to do this CronJobs. Utilising some other website makes the whole process quite opaque for someone who did not set this up.

    Best
    Peter

    1. Hi Peter,

      Thanks for your reaction. I have just realized this morning there is a neater, all OCI way for scheduling function execution: using OCI Monitoring – Healthchecks, we can schedule HTTP requests every X seconds, allowing for even more frequent execution of the function than is available with the IFTTT recipee. I will blog about this shortly – and it is even easier than the use of IFTTT.

      kind regards,
      Lucas

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Next Post

Oracle Cloud Serverless Functions unleashed: exposing OCI Functions through API Gateway

Facebook0TwitterLinkedinOracle Cloud Infrastructure API Gateway makes it possible to expose OCI Functions on public endpoints that do not require complex signed HTTP requests. Any function that should be easily publicly accessible can be given such easy access. By creating an API Deployment on an API Gateway and associating a route […]