Sha256: 682f2d43b5676ec386bd088c85d1bd31116f0c6212c1a142509d3d837e043ce6
Contents?: true
Size: 934 Bytes
Versions: 15
Compression:
Stored size: 934 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 = newsletter @newsletter.with_lock do raise "Newsletter already sent" if @newsletter.sent? @newsletter.update!( 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(organization: @newsletter.organization) .where.not(newsletter_notifications_at: nil, email: nil, confirmed_at: nil) .not_deleted end end end end
Version data entries
15 entries across 15 versions & 1 rubygems