Skip to content

Commit 500f144

Browse files
committed
Initial commit
0 parents  commit 500f144

22 files changed

+756
-0
lines changed

.github/FUNDING.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
github: mylanconnolly

.gitignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/.bundle/
2+
/.yardoc
3+
/_yardoc/
4+
/coverage/
5+
/doc/
6+
/pkg/
7+
/spec/reports/
8+
/tmp/
9+
10+
# rspec failure tracking
11+
.rspec_status

.rspec

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
--format documentation
2+
--color
3+
--require spec_helper

.travis.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
language: ruby
3+
cache: bundler
4+
rvm:
5+
- 2.7.1
6+
before_install: gem install bundler -v 2.1.4

CHANGELOG.md

Whitespace-only changes.

CODE_OF_CONDUCT.md

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as
6+
contributors and maintainers pledge to making participation in our project and
7+
our community a harassment-free experience for everyone, regardless of age, body
8+
size, disability, ethnicity, gender identity and expression, level of experience,
9+
nationality, personal appearance, race, religion, or sexual identity and
10+
orientation.
11+
12+
## Our Standards
13+
14+
Examples of behavior that contributes to creating a positive environment
15+
include:
16+
17+
* Using welcoming and inclusive language
18+
* Being respectful of differing viewpoints and experiences
19+
* Gracefully accepting constructive criticism
20+
* Focusing on what is best for the community
21+
* Showing empathy towards other community members
22+
23+
Examples of unacceptable behavior by participants include:
24+
25+
* The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
* Trolling, insulting/derogatory comments, and personal or political attacks
28+
* Public or private harassment
29+
* Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
* Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
33+
34+
## Our Responsibilities
35+
36+
Project maintainers are responsible for clarifying the standards of acceptable
37+
behavior and are expected to take appropriate and fair corrective action in
38+
response to any instances of unacceptable behavior.
39+
40+
Project maintainers have the right and responsibility to remove, edit, or
41+
reject comments, commits, code, wiki edits, issues, and other contributions
42+
that are not aligned to this Code of Conduct, or to ban temporarily or
43+
permanently any contributor for other behaviors that they deem inappropriate,
44+
threatening, offensive, or harmful.
45+
46+
## Scope
47+
48+
This Code of Conduct applies both within project spaces and in public spaces
49+
when an individual is representing the project or its community. Examples of
50+
representing a project or community include using an official project e-mail
51+
address, posting via an official social media account, or acting as an appointed
52+
representative at an online or offline event. Representation of a project may be
53+
further defined and clarified by project maintainers.
54+
55+
## Enforcement
56+
57+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
58+
reported by contacting the project team at [email protected]. All
59+
complaints will be reviewed and investigated and will result in a response that
60+
is deemed necessary and appropriate to the circumstances. The project team is
61+
obligated to maintain confidentiality with regard to the reporter of an incident.
62+
Further details of specific enforcement policies may be posted separately.
63+
64+
Project maintainers who do not follow or enforce the Code of Conduct in good
65+
faith may face temporary or permanent repercussions as determined by other
66+
members of the project's leadership.
67+
68+
## Attribution
69+
70+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71+
available at [https://contributor-covenant.org/version/1/4][version]
72+
73+
[homepage]: https://contributor-covenant.org
74+
[version]: https://contributor-covenant.org/version/1/4/

Gemfile

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# frozen_string_literal: true
2+
3+
source 'https://rubygems.org'
4+
5+
# Specify your gem's dependencies in task_bot.gemspec
6+
gemspec
7+
8+
gem 'rack-test'
9+
gem 'rake', '~> 12.0'
10+
gem 'rspec', '~> 3.0'

Gemfile.lock

+127
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
PATH
2+
remote: .
3+
specs:
4+
task_bot (0.1.0)
5+
activejob
6+
google-cloud-tasks (~> 2.1)
7+
rack
8+
9+
GEM
10+
remote: https://rubygems.org/
11+
specs:
12+
activejob (6.0.3.4)
13+
activesupport (= 6.0.3.4)
14+
globalid (>= 0.3.6)
15+
activesupport (6.0.3.4)
16+
concurrent-ruby (~> 1.0, >= 1.0.2)
17+
i18n (>= 0.7, < 2)
18+
minitest (~> 5.1)
19+
tzinfo (~> 1.1)
20+
zeitwerk (~> 2.2, >= 2.2.2)
21+
addressable (2.7.0)
22+
public_suffix (>= 2.0.2, < 5.0)
23+
concurrent-ruby (1.1.7)
24+
diff-lcs (1.4.4)
25+
faraday (1.1.0)
26+
multipart-post (>= 1.2, < 3)
27+
ruby2_keywords
28+
gapic-common (0.3.4)
29+
google-protobuf (~> 3.12, >= 3.12.2)
30+
googleapis-common-protos (>= 1.3.9, < 2.0)
31+
googleapis-common-protos-types (>= 1.0.4, < 2.0)
32+
googleauth (~> 0.9)
33+
grpc (~> 1.25)
34+
globalid (0.4.2)
35+
activesupport (>= 4.2.0)
36+
google-cloud-core (1.5.0)
37+
google-cloud-env (~> 1.0)
38+
google-cloud-errors (~> 1.0)
39+
google-cloud-env (1.4.0)
40+
faraday (>= 0.17.3, < 2.0)
41+
google-cloud-errors (1.0.1)
42+
google-cloud-tasks (2.1.1)
43+
google-cloud-core (~> 1.5)
44+
google-cloud-tasks-v2 (~> 0.0)
45+
google-cloud-tasks-v2beta2 (~> 0.0)
46+
google-cloud-tasks-v2beta3 (~> 0.0)
47+
google-cloud-tasks-v2 (0.2.5)
48+
gapic-common (~> 0.3)
49+
google-cloud-errors (~> 1.0)
50+
grpc-google-iam-v1 (>= 0.6.10, < 2.0)
51+
google-cloud-tasks-v2beta2 (0.2.5)
52+
gapic-common (~> 0.3)
53+
google-cloud-errors (~> 1.0)
54+
grpc-google-iam-v1 (>= 0.6.10, < 2.0)
55+
google-cloud-tasks-v2beta3 (0.3.2)
56+
gapic-common (~> 0.3)
57+
google-cloud-errors (~> 1.0)
58+
grpc-google-iam-v1 (>= 0.6.10, < 2.0)
59+
google-protobuf (3.13.0)
60+
googleapis-common-protos (1.3.10)
61+
google-protobuf (~> 3.11)
62+
googleapis-common-protos-types (>= 1.0.5, < 2.0)
63+
grpc (~> 1.27)
64+
googleapis-common-protos-types (1.0.5)
65+
google-protobuf (~> 3.11)
66+
googleauth (0.14.0)
67+
faraday (>= 0.17.3, < 2.0)
68+
jwt (>= 1.4, < 3.0)
69+
memoist (~> 0.16)
70+
multi_json (~> 1.11)
71+
os (>= 0.9, < 2.0)
72+
signet (~> 0.14)
73+
grpc (1.32.0)
74+
google-protobuf (~> 3.13)
75+
googleapis-common-protos-types (~> 1.0)
76+
grpc-google-iam-v1 (0.6.10)
77+
google-protobuf (~> 3.11)
78+
googleapis-common-protos (>= 1.3.10, < 2.0)
79+
grpc (~> 1.27)
80+
i18n (1.8.5)
81+
concurrent-ruby (~> 1.0)
82+
jwt (2.2.2)
83+
memoist (0.16.2)
84+
minitest (5.14.2)
85+
multi_json (1.15.0)
86+
multipart-post (2.1.1)
87+
os (1.1.1)
88+
public_suffix (4.0.6)
89+
rack (2.2.3)
90+
rack-test (1.1.0)
91+
rack (>= 1.0, < 3)
92+
rake (12.3.3)
93+
rspec (3.9.0)
94+
rspec-core (~> 3.9.0)
95+
rspec-expectations (~> 3.9.0)
96+
rspec-mocks (~> 3.9.0)
97+
rspec-core (3.9.3)
98+
rspec-support (~> 3.9.3)
99+
rspec-expectations (3.9.3)
100+
diff-lcs (>= 1.2.0, < 2.0)
101+
rspec-support (~> 3.9.0)
102+
rspec-mocks (3.9.1)
103+
diff-lcs (>= 1.2.0, < 2.0)
104+
rspec-support (~> 3.9.0)
105+
rspec-support (3.9.4)
106+
ruby2_keywords (0.0.2)
107+
signet (0.14.0)
108+
addressable (~> 2.3)
109+
faraday (>= 0.17.3, < 2.0)
110+
jwt (>= 1.5, < 3.0)
111+
multi_json (~> 1.10)
112+
thread_safe (0.3.6)
113+
tzinfo (1.2.7)
114+
thread_safe (~> 0.1)
115+
zeitwerk (2.4.0)
116+
117+
PLATFORMS
118+
ruby
119+
120+
DEPENDENCIES
121+
rack-test
122+
rake (~> 12.0)
123+
rspec (~> 3.0)
124+
task_bot!
125+
126+
BUNDLED WITH
127+
2.1.4

LICENSE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# The MIT License (MIT)
2+
3+
Copyright (c) 2020 Mylan Connolly
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# TaskBot
2+
3+
This gem is designed to allow Google Cloud Task to be used as a backend for
4+
ActiveJob. This could make life a bit easier if you're utilizing something like
5+
Google Cloud Run to serve your Rails app and are looking for a solution for
6+
a background worker.
7+
8+
## Installation
9+
10+
Add this line to your application's Gemfile:
11+
12+
```ruby
13+
gem 'task_bot'
14+
```
15+
16+
And then execute:
17+
18+
$ bundle install
19+
20+
## Usage
21+
22+
First, you'll need to create the Cloud Task queues you wish to interact with.
23+
For more details on that, you can
24+
[check out the documentation](https://cloud.google.com/tasks/docs).
25+
26+
Configure Rails to use this as your ActiveJob backend:
27+
28+
```ruby
29+
Rails.application.config.active_job.queue_adapter = ActiveJob::TaskBot::Adapter.new(
30+
project: 'GOOGLE_CLOUD_PROJECT_ID',
31+
location: 'GOOGLE_CLOUD_LOCATION_ID',
32+
prefix: 'optional-app-prefix',
33+
worker_url: 'https://example-worker-host.com' # DO NOT INCLUDE PATH HERE
34+
)
35+
```
36+
37+
> **NOTE:** If you specify a prefix, your queue name will have that prefix
38+
> added to it. Using the example above, if a job has the queue `default`, it
39+
> will send the job to the queue `optional-app-prefix-default`. If the prefix
40+
> is left nil (the default behavior), then it will look for a queue named
41+
> `default`.
42+
43+
Mount the Rack app in your routes (this is where incoming tasks will be POSTed
44+
to be run):
45+
46+
```ruby
47+
mount TaskBot::Rack, at: '/perform'
48+
```
49+
50+
Enqueue jobs as normal.
51+
52+
## Production Details
53+
54+
Perhaps the most sensible way to run this is to have two Cloud Run services:
55+
56+
1. Web servers (perhaps called `example-web`)
57+
2. Workers (perhaps called `example-worker`)
58+
59+
Both of these will start up Rails, but in this setup you won't have to worry
60+
about scaling behaving properly and your worker requests holding up web
61+
requests, etc. You also have the option of only mounting the `TaskBot::Rack`
62+
app when run as a worker, by mounting it as follows:
63+
64+
```ruby
65+
mount TaskBot::Rack, at: '/perform' if ENV['RAILS_WORKER'].present?
66+
```
67+
68+
TODO: I still have to work out an authorization mechanism to only allow Google
69+
Cloud Tasks at the `/perform` endpoint.
70+
71+
## Development
72+
73+
After checking out the repo, run `bin/setup` to install dependencies. Then,
74+
run `rake spec` to run the tests. You can also run `bin/console` for an
75+
interactive prompt that will allow you to experiment.
76+
77+
To install this gem onto your local machine, run `bundle exec rake install`. To
78+
release a new version, update the version number in `version.rb`, and then run
79+
`bundle exec rake release`, which will create a git tag for the version, push
80+
git commits and tags, and push the `.gem` file to
81+
[rubygems.org](https://rubygems.org).
82+
83+
## Contributing
84+
85+
Bug reports and pull requests are welcome on GitHub at
86+
https://github.com/mylanconnolly/task_bot. This project is intended to be a
87+
safe, welcoming space for collaboration, and contributors are expected to adhere
88+
to the [code of conduct](https://github.com/mylanconnolly/task_bot/blob/master/CODE_OF_CONDUCT.md).
89+
90+
91+
## License
92+
93+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
94+
95+
## Code of Conduct
96+
97+
Everyone interacting in the TaskBot project's codebases, issue trackers, chat
98+
rooms and mailing lists is expected to follow the
99+
[code of conduct](https://github.com/[USERNAME]/task_bot/blob/master/CODE_OF_CONDUCT.md).

Rakefile

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal: true
2+
3+
require 'bundler/gem_tasks'
4+
require 'rspec/core/rake_task'
5+
6+
RSpec::Core::RakeTask.new(:spec)
7+
8+
task default: :spec

bin/console

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
require 'bundler/setup'
5+
require 'task_bot'
6+
7+
# You can add fixtures and/or initialization code here to make experimenting
8+
# with your gem easier. You can also use a different console, if you like.
9+
10+
# (If you use this, don't forget to add pry to your Gemfile!)
11+
# require "pry"
12+
# Pry.start
13+
14+
require 'irb'
15+
IRB.start(__FILE__)

bin/setup

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
IFS=$'\n\t'
4+
set -vx
5+
6+
bundle install
7+
8+
# Do any other automated setup that you need to do here

0 commit comments

Comments
 (0)