Hi there ● Gentaro Terada (@hibariya) ● A programmer who works at ESM, Inc. ● A college student (engineering) ● Likes Ruby, Internet, and Programming ● https://hibariya.org
Motivation: background jobs on GCP? When running Rails applications on GCP (GAE, GKE), where is some possibilities for the place to run its background workers: ● Use Compute Engine ● Create workers on an existing K8s cluster as a deployment ● Use Cloud Run (today I talk about it)
What is Cloud Run It provides a way to run containers on demand. “Cloud Run is a fully managed compute platform that automatically scales your stateless containers. Cloud Run is serverless: it abstracts away all infrastructure management, so you can focus on what matters most—building great applications.” https://cloud.google.com/run/
How to invoke containers: HTTP Containers must have an HTTP interface. Each Cloud Run service has its endpoint URL that exposes the interface. However, from Rails applications, it’s nice for us if we were able to invoke it asynchronous via Active Job interface.
Active Job interface Active Job interfaces are required to implement only two methods: ● enqueue(job) ● enqueue_at(job, time) The interface itself is not so difficult: https://rip.hibariya.org/post/creating-an-active-job-adapter/
Active Job interface for Cloud Run github.com/esminc/activejob-google_cloud_tasks-http Implemented a simple Active Job interface to run jobs via Cloud Tasks.
ActiveJob::GoogleCloudTasks::HTTP It provides: ● An Active Job interface ● A simple Rack application to expose HTTP interface for Cloud Run It does not provide: ● Authentication mechanism for the Rack app
Summary ● Cloud Run provides a way to run containers on demand. ● We can even use it for Active Job backend with github.com/esminc/activejob-google_cloud_tasks-http . ● Implementing Active Job interface itself is not so difficult.