Guest User

Untitled

a guest
Jul 17th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. def refresh
  2. json = Rails.cache.fetch('json-all', :expires_in => 1.seconds) do
  3. json = {}
  4. json[:server_time] = Time.zone.now.to_i
  5. items = Item.all :conditions => { :et => { "$gt" => Time.now }}
  6. json[:items] = {}
  7. items.each do |item|
  8. time = (item.et - Time.zone.now)
  9. hours = (time/3600).to_i
  10. minutes = (time/60 - hours * 60).to_i
  11. seconds = (time - (minutes * 60 + hours * 3600))
  12. json[:items][item.id.to_s.to_sym] = {}
  13. json[:items][item.id.to_s.to_sym][:price] = item.price.to_f / 100
  14. json[:items][item.id.to_s.to_sym][:et] = "%02d:%02d:%02d" % [hours, minutes, seconds]
  15. json[:items][item.id.to_s.to_sym][:bids] = item.bids
  16. json[:items][item.id.to_s.to_sym][:state] = item.et > Time.now ? "online" : "completed"
  17. end
  18. logger.info { ">>> Clear cache" }
  19. json
  20.  
  21. end
  22. render :json => json.to_json
  23. end
Add Comment
Please, Sign In to add comment