我需要在固定时间(例如下午 1 点、下午 3 点、上午 9 点)调用 tweeter api。我正在使用 twiter gem 和 rufus-scheduler
这是我的模型
class Feed < ActiveRecord::Base
def self.latest
order('created_at desc').take(500)
end
def self.pull_tweets
$client.search("#ukraine", since_id: maximum(:tweet_id), count: 10).take(10).each do |tweet|
create!(
tweet_id: tweet.id,
content: tweet.text,
screen_name: tweet.user.screen_name,
)
end
end
end
这是我使用调度程序调用 pull_tweets 的控制器
class FeedsController < ApplicationController
def index
scheduler = Rufus::Scheduler.new
scheduler.schedule_every('60s') do
Feed.pull_tweets
end
@tweets = Feed.latest
end
end
它工作得很好,但是我如何设置多个时间,比如凌晨 1 点、下午 3 点、上午 9 点,以便根据用户输入来安排任务?