Skip to content

agendrix/pg-cron-rails

Repository files navigation

pg_cron Rails

pg_cron jobs scheduling for Rails applications

Configuration

By default, no configuration is needed to use this gem.

PgCronRails schedules your pg_cron jobs in the default PSQL database using your current database connection user.

You can also customize PgCronRails database connection configuration by creating an initializer:

PgCronRails.configure do |config|
    config.connection_config =  {
        username: username
        password: password
        database: database
    }
end

Usage

Create pg_cron job

  1. Generate a job:
rails generate pg_cron_job daily_vacuum
      create  db/pg_cron_jobs/daily_vacuum.yml
      create  db/migrate/[TIMESTAMP]_add_daily_vacuum_pg_cron_job.rb
  1. Define db/pg_cron_jobs/daily_vacuum.yml job params.
daily_vacuum:
    cron: "3 5 * * *"
    statement: "VACUUM VERBOSE ANALYZE"
    database: <%= ActiveRecord::Base.connection.current_database %> # This parameter is optional
  1. Run the migration
rails db:migrate

Methods

The methods added to ActiveRecord::Migration are defined in PgCronRails::Statements

License

The gem is available as open source under the terms of the MIT License.

About

pg_cron jobs scheduling for Rails

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages