Class: SendSummaryEmailsJob

Inherits:
ApplicationJob show all
Defined in:
/var/apps/qpixel/app/jobs/send_summary_emails_job.rb

Instance Method Summary collapse

Methods inherited from ApplicationJob

#exec, #initialize, #logger

Constructor Details

This class inherits a constructor from ApplicationJob

Instance Method Details

#performObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File '/var/apps/qpixel/app/jobs/send_summary_emails_job.rb', line 4

def perform
  staff = User.where(staff: true)
  posts = Post.unscoped.qa_only.where(created_at: SummaryMailer::TIMEFRAME.ago..DateTime.now)
              .includes(:community, :user)
  flags = Flag.unscoped.where(created_at: SummaryMailer::TIMEFRAME.ago..DateTime.now)
              .includes(:post, :community, :user)
  comments = Comment.unscoped.where(created_at: SummaryMailer::TIMEFRAME.ago..DateTime.now)
                    .includes(:user, :post, :comment_thread, post: :community)
  users = User.where(created_at: SummaryMailer::TIMEFRAME.ago..DateTime.now).includes(:community_users)
  staff.each do |u|
    SummaryMailer.with(to: u.email, posts: posts.to_a, flags: flags.to_a, comments: comments.to_a, users: users.to_a)
                 .content_summary
                 .deliver_later
  end

  logger.info "Scheduled send of #{staff.size} emails."
end