Skip to content
This repository has been archived by the owner on Apr 17, 2020. It is now read-only.

kawabatas/activejob-google_cloud_tasks

Repository files navigation

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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •