Introduction and background
The Serverless Migration Station mini-series helps App Engine builders modernize their apps to the newest language runtimes, similar to from Python 2 to three or Java 8 to 17, or to sister serverless platforms Cloud Capabilities and Cloud Run. One other purpose of this sequence is to show find out how to transfer away from App Engine’s unique APIs (now known as legacy bundled companies) to Cloud standalone alternative companies. As soon as now not depending on these proprietary companies, apps change into rather more transportable, making them versatile sufficient to:
App Engine’s Job Queue service gives infrastructure for executing duties outdoors of the usual request-response workflow. Duties might encompass workloads exceeding request timeouts or periodic tangential work. The Job Queue service gives two completely different queue varieties, push and pull, for builders to carry out auxiliary work.
Push queues are coated in Migration Modules 7-9, demonstrating find out how to add use of push duties to an present baseline app adopted by steps emigrate that performance to Cloud Duties, the standalone successor to the Job Queues push service. We flip to pull queues in right now’s video the place Module 18 demonstrates find out how to add use of pull duties to the identical baseline pattern app. Module 19 follows, displaying find out how to migrate that utilization to Cloud Pub/Sub.
Including use of pull queues
Along with registering web page visits, the pattern app must be modified to trace guests. Visits are comprised of a timestamp and customer data such because the IP tackle and person agent. We’ll modify the app to make use of the IP tackle and observe what number of visits come from every tackle seen. The house web page is modified to point out the highest guests along with the newest visits:
|The pattern app’s up to date residence web page monitoring visits and guests|
When visits are registered, pull duties are created to trace the guests. The pull duties sit patiently within the queue till they’re processed in combination periodically. Till that occurs, the highest guests desk stays static. These duties might be processed in a variety of methods: periodically by a
cron or Cloud Scheduler job, a separate App Engine backend service, explicitly by a person (through browser or command-line HTTP request), event-triggered Cloud Perform, and so on. Within the tutorial, we subject a
curl request to the app’s endpoint to course of the enqueued duties. When all duties have accomplished, the desk then displays any adjustments to the present prime guests and their go to counts:
|Processed pull duties replace the highest guests desk|
Beneath is a few pseudocode representing the core a part of the app that was altered so as to add Job Queue pull job utilization, specifically a brand new information mannequin class,
VisitorCount, to trace customer counts, enqueuing a (pull) job to replace customer counts when registering particular person visits in
store_visit(), and most significantly, a brand new operate
fetch_counts(), accessible through
/log, to course of enqueued duties and replace general customer counts. The bolded traces symbolize the brand new or altered code.
|Including App Engine Job Queue pull job utilization to pattern app|
This “migration” is comprised of including Job Queue pull job utilization to assist monitoring customer counts to the Module 1 baseline app and arrives on the end line with the Module 18 app. To get hands-on expertise doing it your self, do the codelab by hand and comply with together with the video. Then you definitely’ll be able to improve to Cloud Pub/Sub must you select to take action.
In Fall 2021, the App Engine group prolonged assist of most of the bundled companies to 2nd technology runtimes (which have a 1st technology runtime), which means you’re now not required emigrate pull duties to Pub/Sub when porting your app to Python 3. You may proceed utilizing Job Queue in your Python 3 app as long as you retrofit the code to entry bundled companies from next-generation runtimes.
For those who do need to transfer to Pub/Sub, see Module 19, together with its codelab. All Serverless Migration Station content material (codelabs, movies, and supply code) can be found at its open supply repo. Whereas we’re initially specializing in Python customers, the Cloud group is masking different runtimes quickly, so keep tuned. Additionally try different movies within the broader Serverless Expeditions sequence.