Repository is archived
No commit activity in last 3 years
No release in over 3 years
Google Cloud Tasks adapter for ActiveJob
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.17
~> 12.3
~> 3.0

Runtime

>= 0.2.6, < 1.2.0
>= 2.0.6
 Project Readme

Activejob::GoogleCloudTasks

Build Status Gem Version

Google Cloud Tasks adapter for ActiveJob

Prerequisites

Installation

Add this line to your application's Gemfile:

gem 'activejob-google_cloud_tasks', '>= 0.1.2'

Usage

First, change the ActiveJob backend.

Rails.application.config.active_job.queue_adapter = Activejob::GoogleCloudTasks::Adapter.new(
  project: 'MY_GOOGLE_CLOUD_TASKS_PROJECT',
  location: 'MY_GOOGLE_CLOUD_TASKS_LOCATION'
)

Second, mount the rack application.

Rails.application.routes.draw do
  mount Activejob::GoogleCloudTasks::Rack, at: Activejob::GoogleCloudTasks::Config.path
end

Write the Job class and code to use it.

Note: perform argument is one and it must be hash.

class SampleJob < ApplicationJob
  queue_as :default
  def perform(args)
    puts "hello, #{args[:name]}!"
  end
end
class SampleController < ApplicationController
  def job
    SampleJob.perform_later({name: 'ken'})
  end
end

kawabatas/rails_activejob_sample is rails example.

Configuration

Adapter

Rails.application.config.active_job.queue_adapter = Activejob::GoogleCloudTasks::Adapter.new(
  project: 'MY_GOOGLE_CLOUD_TASKS_PROJECT',
  location: 'MY_GOOGLE_CLOUD_TASKS_LOCATION',

  cloud_tasks_client: Google::Cloud::Tasks.new(
    version: :v2beta3,
    credentials: 'path/to/keyfile.json'
  )
)

Argument Reference

  • project - (Required) The ID of the Google Cloud project in which the Cloud Tasks belongs.

  • location - (Required) The Location of the Cloud Tasks.

  • cloud_tasks_client - (Optional) The instance of Google::Cloud::Tasks. Please see Google::Cloud::Tasks.new for details. Default: Google::Cloud::Tasks.new(version: :v2beta3)

Config

Activejob::GoogleCloudTasks::Config.path = '/foo'
  • path - (Optional) The path which the Cloud Tasks service forwards the task request to the worker. Default: /activejobs

Development

$ bundle exec rake spec

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/kawabatas/activejob-google_cloud_tasks.

License

The gem is available as open source under the terms of the MIT License.