Home > Software design >  How can I perform a worker when a date of my table is equal to current date - Ruby on Rails
How can I perform a worker when a date of my table is equal to current date - Ruby on Rails

Time:08-12

How can I perform a worker when a date of my table is equal to current date on Ruby on Rails 7.0, I'm using Sidekiq and Sidekiq Schedule and I have this table

class CreateDraws < ActiveRecord::Migration[7.0]
  def change
    create_table :draws do |t|

      t.string :name
      t.integer :porcentual
      t.datetime :datefrom
      t.datetime :dateto
      t.string :firstAward
      t.string :secondAward
      t.integer :first_winner, default: nil
      t.integer :second_winner, default: nil
      t.integer :n_ticket
      t.integer :limit
      t.integer :number_solds, default: 0
      t.boolean :has_winners, default: false

      t.timestamps
    end
  end
end

I want to perform a worker always when dateto is equal than current date

CodePudding user response:

dateto is static data. You need an action or event to trigger your worker's job.

For example:

  1. After the record is created, queue a job
  2. On an hourly schedule, query the database filtering records on dateto being the current date

Within the job, you can perform behavior with your records, even if that behavior is to do nothing.

  • Related