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
Tweet

More Decks by Hibariya Hi

Other Decks in Programming

Transcript

  1. Creating an Active Job
    Adapter for Cloud Run
    2020/02/04 Tokyo Rubyist Meetup (Rubyist show and tell)
    @Impact Hub Tokyo

    View Slide

  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

    View Slide

  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)

    View Slide

  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/

    View Slide

  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)

    View Slide

  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.

    View Slide

  7. Run jobs asynchronous from Rails apps
    Cloud Run
    Cloud Tasks
    enqueue HTTP request

    View Slide

  8. 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/

    View Slide

  9. 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.

    View Slide

  10. 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

    View Slide

  11. Usage: configure, implement, and mount

    View Slide

  12. Run jobs asynchronous from Rails apps
    Cloud Run
    Cloud Tasks
    enqueue HTTP request
    POST /_jobs
    XXJob.perform_later

    View Slide

  13. 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.

    View Slide