Activejob::GoogleCloudTasks
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 ofGoogle::Cloud::Tasks
. Please seeGoogle::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.