rubyonjets/jets

How to set db pool size for a particular Active Job?

Closed this issue · 2 comments

We have a job that needs much higher database concurrency than the rest of our application. Is there a way to override the database pool size just for this job?

If the database.yml is using env vars. 🧐 For example:

config/database.yml

default: &default
  adapter: mysql2
  encoding: utf8mb4
  pool: <%= ENV["DB_POOL"] || 5  %>
  database: <%= ENV['DB_NAME'] || 'demo_development' %>
  username: <%= ENV['DB_USER'] || 'root' %>
  password: <%= ENV['DB_PASS'] %>
  host: <%= ENV["DB_HOST"] %>
  url: <%= ENV['DATABASE_URL'] %> # takes higher precedence than other settings
  reconnect: true

development:
  <<: *default
  database: <%= ENV['DB_NAME'] || 'demo_development' %>

test:
  <<: *default
  database: demo_test

production:
  <<: *default
  database: demo_production
  url: <%= ENV['DATABASE_URL'] %>

Could then use an env var to set the DB_POOL. Example:

app/jobs/hard_job.rb

class HardJob < ApplicationJob
  rate "10 hours" # every 10 hours
  environment(
    DB_POOL: 10
  )
  def dig
    puts "done digging"
  end
end

Some related docs 👍 https://rubyonjets.com/docs/function-properties/

awesome thanks! Didn't realize environment could be overloaded within the job!