Sha256: 486a6cf2fbec0f92fb5df4ca0a1743f6b8a2083d9c0e9bee272195e51b81181d
Contents?: true
Size: 795 Bytes
Versions: 8
Compression:
Stored size: 795 Bytes
Contents
# frozen_string_literal: true module Decidim module Admin # Custom ApplicationJob scoped to the admin panel. # class NewsletterJob < ApplicationJob queue_as :newsletter def perform(newsletter) newsletter.with_lock do raise "Newsletter already sent" if newsletter.sent? newsletter.update_attributes!( sent_at: Time.current, total_recipients: recipients.count, total_deliveries: 0 ) end recipients.find_each do |user| NewsletterDeliveryJob.perform_later(user, newsletter) end end private def recipients @recipients ||= User.where(newsletter_notifications: true).where.not(email: nil, confirmed_at: nil) end end end end
Version data entries
8 entries across 8 versions & 2 rubygems