rufus gem 如何在停止另一项工作的同时保留一份工作 运行

rufus gem how to keep one job running while stopping the other

    This is my scheduler.rb in my initializer file

    unless defined?(Rails::Console) || File.split([=12=]).last == 'rake'
 s = Rufus::Scheduler.singleton
 s.every '1m', :tag => 'main_process' do
   Rails.logger.info "hello, it's #{Time.now}"
   Rails.logger.flush
   Bid.all.each do |bid|
     id = bid.event_id
      puts "*" * 50
      puts bid.id
      puts bid.event_id
      puts "*" * 50
       # @price = BuyNowBid.find_by(bid_id: params[:bid_id])
      @events = Unirest.get("https://api.seatgeek.com/2/events/#{id}?&client_id=NjQwNTEzMXwxNDgxNDkxODI1").body
      if @events["stats"]
        @low = @events["stats"]["lowest_price"] || 0
        @avg = @events["stats"]["average_price"] || 0
        BuyNowBid.create(bid_id: bid.id, lowest_price: @low , average_price: @avg)

        if @low <= bid.bid
          send_message("+13125501444", "Lowest price matched! Buy your ticket now!")
          bid.bid = 0
          bid.save
        end

      else
        puts 'problem with @events?'
        p @events
      end


   end
 end

结束

def send_message(phone_number, alert_message) account_sid = "" auth_token = ""

    @client = Twilio::REST::Client.new account_sid, auth_token
    @twilio_number = "" 
    message = @client.messages.create(
      :from => @twilio_number,
      :to => phone_number,
      :body => alert_message
    )
    puts message.to
  end

所以我 运行 的工作是每分钟从 api 中提取最低价格,当最低价格与某人的出价相匹配时,他们会收到一条文本通知,尽管它有效,我遇到的问题是我希望工作保持 运行 在我从 api 获得最低价格的任何时候,但我不希望用户继续收到相同的文本通知每一分钟。

现在我有它,所以不会发生这种情况,但在匹配出价后,它实际上已从数据库中删除。所以基本上我问的是如何保持每分钟 scraping api 的最低价格出价匹配,但只向用户发送一个文本通知他们出价匹配并且不必从数据库中删除该出价。

我真的想多了,我刚刚在我的出价 table 上创建了一个名为保存出价的新列,并在它变为零之前将其设置为 bid.bid

     @events = Unirest.get("https://api.seatgeek.com/2/events/#{id}?&client_id=NjQwNTEzMXwxNDgxNDkxODI1").body

      if @events["stats"]
        @low = @events["stats"]["lowest_price"] || 0
        @avg = @events["stats"]["average_price"] || 0
        BuyNowBid.create(bid_id: bid.id, lowest_price: @low , average_price: @avg)

        if @low <= bid.bid
          send_message("+13125501444", "Lowest price matched for #{@events["title"]} ! Buy your ticket now for #{bid.saved_bid}!")
          **bid.saved_bid = bid.bid**
          bid.bid = 0
          bid.save