Skip to content

Commit

Permalink
Auto-deciding older tips
Browse files Browse the repository at this point in the history
  • Loading branch information
sashazykov committed Jul 2, 2014
1 parent cea7db1 commit e8ad717
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
13 changes: 11 additions & 2 deletions app/models/tip.rb
Expand Up @@ -66,12 +66,21 @@ def undecided?
def self.refund_unclaimed
unclaimed.non_refunded.
where.not(decided_at: nil).
where('tips.decided_at < ?', Time.now - 1.month).
where('tips.decided_at < ?', 1.month.ago).
find_each do |tip|
tip.touch :refunded_at
end
end

def self.auto_decide_older_tips
undecided.non_refunded.
where('tips.created_at < ?', 1.month.ago).
find_each do |tip|
tip.amount_percentage = 1
tip.save
end
end

def commit_url
project.commit_url(commit)
end
Expand All @@ -81,7 +90,7 @@ def amount_percentage
end

def amount_percentage=(percentage)
if undecided? and percentage.present? and %w(0 0.1 0.5 1 2 5).include?(percentage)
if undecided? and percentage.present? and %w(0 0.1 0.5 1 2 5).include?(percentage.to_s)
self.amount = (project.available_amount * (percentage.to_f / 100)).ceil
end
end
Expand Down
3 changes: 3 additions & 0 deletions lib/bitcoin_tipper.rb
Expand Up @@ -39,6 +39,9 @@ def self.work withdraw = true
end
end

Rails.logger.info "Auto-deciding older tips..."
Tip.auto_decide_older_tips

Rails.logger.info "Refunding unclaimed tips..."
Tip.refund_unclaimed

Expand Down

0 comments on commit e8ad717

Please sign in to comment.