Created
July 30, 2014 17:43
-
-
Save jmzbond/31ac1c12d2bc700bebbf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#config/initializers/fist_of_fury.rb | |
# Ensure the jobs run only in a web server. | |
if defined?(Rails::Server) | |
FistOfFury.attack! do | |
# Jobs can be scheduled here. Example: | |
# SayHiJob.recurs { secondly(3) } | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#app/jobs/recurring.rb | |
class Recurring | |
include SuckerPunch::Job | |
include FistOfFury::Recurrent | |
recurs { daily } | |
def perform | |
ActiveRecord::Base.connection_pool.with_connection do | |
# Auto set status to in progress from connected | |
Borrow.where(status1: 2).select { |b| b.request.pickupdate == Date.today }.each { |b| b.update_attributes(status1 == 3 ) } | |
# Auto set status to complete and connect borrowers/lenders for return | |
Borrow.where(status1: 3).select { |b| b.request.returndate == Date.today }.each do |b| | |
b.update_attributes(status1 == 4 ) | |
RequestMailer.return_reminder(b).deliver | |
end | |
# Auto set status to N/A if borrows are still outstanding on their pickup date | |
Borrow.where(status1: 1).select { |b| b.request.pickupdate == Date.today}.each do |b| | |
b.update_attributes(status1 == 20) | |
RequestMailer.not_found(b, b.itemlist_id).deliver | |
end | |
# Auto email lenders every other day if they have outstanding requests | |
lender_array = Array.new | |
Inventory.where(id: (Borrow.where(status1:1).all.pluck("inventory_id"))).each { |i| lender_array << i.signup.id } | |
lender_array.uniq.each { |l|InventoryMailer.outstanding_request(l).deliver } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment