Class: CleanupVotesJob
- Inherits:
-
ApplicationJob
- Object
- ActiveJob::Base
- ApplicationJob
- CleanupVotesJob
- Defined in:
- /var/apps/qpixel/app/jobs/cleanup_votes_job.rb
Instance Method Summary collapse
Methods inherited from ApplicationJob
Constructor Details
This class inherits a constructor from ApplicationJob
Instance Method Details
#perform ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File '/var/apps/qpixel/app/jobs/cleanup_votes_job.rb', line 4 def perform Community.all.each do |c| logger.tagged(c.name) do RequestContext.community = c orphan_votes = Vote.all.reject { |v| v.post.present? } logger.info "Removing #{orphan_votes.length} #{'orphan vote'.pluralize(orphan_votes.length)}" system_user = User.find(-1) orphan_votes.each do |v| result = v.destroy if result AuditLog.admin_audit( comment: "Deleted orphaned vote for user ##{v.recv_user_id} " \ "on post ##{v.post_id} " \ "in community ##{c.id} (#{c.name})", event_type: 'vote_delete', related: v, user: system_user ) else logger.warn "Failed to remove vote #{v.id}. Validations follow." v.errors..each do |msg| logger.warn msg end end end end end end |