Implement global cron job in apigee edge

I need a cron job in which I check some logic then assign the result to global variables. Then, multiple proxies check this global variable to do some logic.

Could you help tell me how to create a cron job in APIGEE?. I see the thread: https://community.apigee.com/questions/27019/schedule-a-thread-in-apigee-edge.html

but do not know how to inject nodejs as suggested in the answer.

0 6 966
6 REPLIES 6

@Dino

Could you help?. Thanks

There's no facility to run a cron job within Apigee Edge.

I can suggest Google Cloud Scheduler, which is designed for running scheduled tasks. Check it out!

There is no such thing as a "global variable" in Apigee Edge. There are things like KeyValueMaps and Caches and so on.

The task run by cloud scheduler could invoke API proxies that would then set data into those assets.

Thanks. How about the suggested answer in the link above i.e using nodejs to setup cronjob running in background?

The traditional Node.js support on Apigee Edge Cloud, as described in this topic, is deprecated. For details on the deprecation, see the Deprecations and retirements page. This feature will be retired in the future.

So I cannot recommend that.

You can of course build a cron job like thing in nodejs, using the hosted target. This package looks very popular. https://www.npmjs.com/package/cron That would run in your hosted target.


EDIT - two things

  1. There is some trickiness to doing this. You need to coordinate among the possible App Engine instances - if you want a single process to handle the cron job, you would need to conduct an election and select a leader (maybe via raft). This is not simple because you don't know the count of servers, and you don't know where in the network these servers might reside. There's no guarantee of direct network connectivity between the instances. (you are not directly managing the HT instances)
  2. the hosted target processes can be quiesced. This means the elected leader might disappear. It's possible that you could have zero instances, which means the foundation for your "cron" behavior is gone.

In short, HT is not a good basis upon which to build cron. Better advice: Use Google Cloud Scheduler or some other task-scheduler-as-a-service.

hosted target is interesting. However, it is attached to proxies as target server so can you confirm the life cycle of NodeJS app hosted in hosted target?. If I use cron job there, does the app continuously run and does not depend on any attached proxy lifecycle? I need this nodeJS app runs forever

You are correct - Hosted Target runs on google App Engine, with a min instances of 0. This means the hosted target process (in nodejs) can be reaped when there are no requests flowing through the system.

So my prior suggestion was off base. Let me correct that: It is inappropriate to try to use the Hosted Target feature as a foundation for an always-on, reliable cron, or task scheduler.

Fortunately, there are good options open to you. Google Cloud Scheduler is a good one.

There is no task scheduler or cron mechanism in Apigee Edge.