簡體   English   中英

更新數據庫每月紅寶石的軌道?

[英]Update database monthly ruby on rails?

我有一個帶有整數列“ monthly_point”的表“ Point”和一個帶有整數列“ Give_Point”的表“ User”。 我想每個月更新“ Give_Point”的值是“ monthly_point”的值。 我怎樣才能做到這一點? 謝謝大家

有一個用於執行此類任務的工具,稱為sidetiq

它使用sidekiq進行后台作業。

這是一個例子

class MonthlyPointWorker
  include Sidekiq::Worker
  include Sidetiq::Schedulable

  recurrence { monthly }

  def perform
    # do your work here
  end
end

每當將任務放入crontab並使用cron執行它時。

由您決定使用哪一種來滿足您的需求。

您應該使用cron-jobs來實現這一目標, whenever gem添加gem'whenever gem 'whenever', require: false到Gemfile並運行bundle install 然后在應用程序的根目錄中,運行以下命令:

`bundle exec wheneverize`

這會將日程表文件添加到您的config文件夾(config/schedule.rb) 該文件是您設置計划任務的地方。 您可以使用常規的cron調度,也可以使用更慣用的DSL進行調度。 以下示例摘自gem的README.md:

every 3.hours do
  runner "MyModel.some_process"
  rake "my:rake:task"
  command "/usr/bin/my_great_command"
end

every 1.day, :at => '4:30 am' do
  runner "MyModel.task_to_run_at_four_thirty_in_the_morning"
end

every :hour do # Many shortcuts available: :hour, :day, :month, :year, :reboot
  runner "SomeModel.ladeeda"
end

every :sunday, :at => '12pm' do # Use any day of the week or :weekend, :weekday
  runner "Task.do_something_great"
end

every '0 0 27-31 * *' do
  command "echo 'you can use raw cron syntax too'"
end`

config/schedule.rb設置計划任務后,仍然需要將其應用於crontab。 在終端上,使用everything命令更新您的crontab:

轉到應用程序的目錄。

cd /my/app

查看config / schedule.rb轉換為cron語法

bundle exec whenever

每當寶石

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM