esminc / activejob-google_cloud_tasks-http Goto Github PK
View Code? Open in Web Editor NEWActive Job adapter for Google Cloud Tasks HTTP targets
License: MIT License
Active Job adapter for Google Cloud Tasks HTTP targets
License: MIT License
Just a heads up. This error get's raised when scheduling.
How can I schedule a job in the near future? Any sample code? Thanks in advance.
In the README, it states the following:
Note that this rack app itself does not have any authentication mechanism.
I am looking to add a simple HTTP Basic AUTH to the rack app, but can't see an obvious way to allow Google Tasks API to specify these credentials when posting to the jobs URL.
Hi @hibariya, great gem. Cloud Tasks look like they'll make my async tasks way simpler and cheaper to host!
I'm having trouble with some of my jobs failing however and don't seem to be seeing any output in the normal Rails log. I'm assuming that's because Rack is unable to access the Rails loggers, but I'm new to mounting Rack apps inside Rails ones so I apologize if I'm just confused.
Is there an easy way to expose the Rails logger to your Rack component? Alternately, would you be open to a PR which extracted the logic for running the jobs from your Rack component so I could mix it into a Rails controller?
Thank-you, and please let me know if you need more specific information to give an answer. I'm away from my code right now but can get you code samples later.
Cheers!
I'm receiving the following:
ArgumentError (wrong number of arguments (given 3, expected 0; required keywords: project, location, queue))
This is when adapter tries to call queue_path
. This is likely due to changes in Google's Ruby libraries.
I build my app in a Docker container and use assets:precompile so the app has faster cold starts. When deploying this on production I hit an error because the environment variable I use for Google credentials was not available for the precompile step (assets:precompile runs all config and initializers).
Error in Docker build:
Step #1: Step 17/23 : RUN SECRET_KEY_BASE=1 bundle exec rake assets:precompile
Step #1: ---> Running in c8abbe14a1b3
Step #1: rake aborted!
Step #1: TypeError: no implicit conversion of nil into String
Step #1: /usr/src/app/config/environments/production.rb:125:in `block in <top (required)>'
relevant production.rb snippet (with some sensitive data obscured):
config.active_job.queue_adapter = ActiveJob::GoogleCloudTasks::HTTP::Adapter.new(
project: 'my-project',
location: 'europe-west2',
url: 'https://www.example.com/jobs',
client: Google::Cloud::Tasks.new(
version: :v2beta3,
credentials: JSON.parse(ENV["GOOGLE_CLOUD_PRODUCTION_KEYFILE"]) # production.rb:125
)
)
The environment variable does not exist yet, nor do I want to include it in the build steps. It's annoying because this is being called by assets:precompile which in no way affects Active Job or Google Cloud Tasks. Ideally it just wouldn't run this at all.
After a few too many hours of frustration I came across a reasonable workaround (via https://stackoverflow.com/a/58017606/3471900):
unless ARGV.include?("assets:precompile") # wrap the config so it doesn't run when assets:precompile is called
config.active_job.queue_adapter = ActiveJob::GoogleCloudTasks::HTTP::Adapter.new(
project: 'my-project',
location: 'europe-west2',
url: 'https://www.example.com/jobs',
client: Google::Cloud::Tasks.new(
version: :v2beta3,
credentials: JSON.parse(ENV["GOOGLE_CLOUD_PRODUCTION_KEYFILE"])
)
)
end
Ideally this would be handled natively by the gem, but if not, perhaps adding a section to the readme or wiki would help others and future me :) Quick draft suggestion:
Error when calling assets:precompile?
If you call assets:precompile, all configs and initializers are loaded. If you load your credentials via environment variables they may not be available and the adapter will error. To solve this, wrap the queue_adapter
config in a unless ARGV.include?("assets:precompile")
condition. Eg.
unless ARGV.include?("assets:precompile") # prevents running on assets:precompile
Rails.application.config.active_job.queue_adapter = ActiveJob::GoogleCloudTasks::HTTP::Adapter.new(
project: 'my-project',
location: 'europe-west2',
# ...
)
end
PS. Thank you for the gem! It works great and got me up and running with Cloud Tasks super quickly :)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.