skill-assessment-app/app/workers/reminder.rb
Mark Moser 4bbd93ded1 rubocop noise: fixes FrozenStringLiteralComment
Adding the .ruby-verison file triggered previously un-run cops, specifically:

  This cop is designed to help upgrade to Ruby 3.0. It will add the
  comment `# frozen_string_literal: true` to the top of files to enable
  frozen string literals. Frozen string literals will be default in Ruby
  3.0. The comment will be added below a shebang and encoding comment. The
  frozen string literal comment is only valid in Ruby 2.3+.

More info on rubocop [Automatic-Corrections](https://github.com/bbatsov/rubocop/wiki/Automatic-Corrections)
2016-09-08 10:30:13 -05:00

39 lines
976 B
Ruby

# frozen_string_literal: true
class Reminder
def initialize
@collection = reminder_collection
end
def count
@collection.count
end
alias size count
def candidates
Candidate.includes(:recruiter).where(id: @collection.map { |row| row['id'] })
end
def send_all
candidates.each do |candidate|
CandidateMailer.reminder(candidate).deliver_now
flag_as_reminded candidate.id
end
end
private
def reminder_collection
sql = "select c.id, c.test_hash, c.name, c.email, max(a.updated_at) last_updated
from candidates c
inner join answers a on a.candidate_id = c.id
where completed = false and reminded = false
group by c.id
having MAX(a.updated_at) < DATE_SUB(NOW(), INTERVAL 24 HOUR);"
ActiveRecord::Base.connection.exec_query(sql)
end
def flag_as_reminded candidate_id
Candidate.find(candidate_id).update(reminded: true)
end
end