Sha256: fdbb3082366a4eb6dcd42d6a46ebe8db4e39fbf5ac214df1785c88b6de98d03f
Contents?: true
Size: 1.29 KB
Versions: 51
Compression:
Stored size: 1.29 KB
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, form, recipients_ids) @newsletter = newsletter @form = form @recipients_ids = recipients_ids @newsletter.with_lock do raise "Newsletter already sent" if @newsletter.sent? @newsletter.update!( sent_at: Time.current, extended_data: extended_data, total_recipients: recipients.count, total_deliveries: 0 ) end recipients.find_each do |user| NewsletterDeliveryJob.perform_later(user, @newsletter) end end private def extended_data { send_to_all_users: @form["send_to_all_users"], send_to_followers: @form["send_to_followers"], send_to_participants: @form["send_to_participants"], participatory_space_types: @form["participatory_space_types"], scope_ids: @form["scope_ids"] } end def recipients @recipients ||= User.where(organization: @newsletter.organization) .where(id: @recipients_ids) end end end end
Version data entries
51 entries across 51 versions & 1 rubygems