Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Creating an Active Job Adapter for Cloud Run

Hibariya Hi
February 04, 2020

Creating an Active Job Adapter for Cloud Run

Talked about "what is Google Cloud Run" and "how to create an Active Job adapter"

Hibariya Hi

February 04, 2020

More Decks by Hibariya Hi

Other Decks in Programming


  1. Creating an Active Job Adapter for Cloud Run 2020/02/04 Tokyo

    Rubyist Meetup (Rubyist show and tell) @Impact Hub Tokyo
  2. Hi there • Gentaro Terada (@hibariya) • A programmer who

    works at ESM, Inc. • A college student (engineering) • Likes Ruby, Internet, and Programming • https://hibariya.org
  3. 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)
  4. 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/
  5. What can be done with Cloud Run • To run

    background/batch jobs • To run web apps • To manage cloud resources (shutting down staging during nighttime)
  6. 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.
  7. 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/
  8. 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
  9. Run jobs asynchronous from Rails apps Cloud Run Cloud Tasks

    enqueue HTTP request POST /_jobs XXJob.perform_later
  10. 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.