Sha256: 780f7528e62d78c3b1c99c550e3fa6013142f2b935103b95a1cad893da98ede4

Contents?: true

Size: 1.11 KB

Versions: 16

Compression:

Stored size: 1.11 KB

Contents

# rake effective_polls:send_notifications

namespace :effective_polls do
  desc 'Send email notifications for effective polls'
  task send_notifications: :environment do
    puts 'Sending notifications'

    table = ActiveRecord::Base.connection.table_exists?(:poll_notifications)
    blank_tenant = defined?(Tenant) && Tenant.current.blank?

    if table && !blank_tenant
      poll_notifications = Effective::PollNotification.deep.notifiable

      poll_notifications.find_each do |notification|
        begin
          notified = notification.notify!
          puts "Sent #{notification.category} for #{notification.poll}" if notified
        rescue StandardError => e
          data = { poll_notification_id: notification.id, poll_id: notification.poll_id }
          ExceptionNotifier.notify_exception(e, data: data) if defined?(ExceptionNotifier)
          puts "Error with effective poll_notification #{notification.id}: #{e.errors.inspect}"
        end
      end
    end

    puts 'All done'
  end

  # Deprecated version
  task notify: :environment do
    Rake::Task['effective_polls:send_notifications'].invoke
  end

end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
effective_polls-0.7.3 lib/tasks/effective_polls_tasks.rake
effective_polls-0.7.2 lib/tasks/effective_polls_tasks.rake
effective_polls-0.7.1 lib/tasks/effective_polls_tasks.rake
effective_polls-0.7.0 lib/tasks/effective_polls_tasks.rake
effective_polls-0.6.2 lib/tasks/effective_polls_tasks.rake
effective_polls-0.6.1 lib/tasks/effective_polls_tasks.rake
effective_polls-0.6.0 lib/tasks/effective_polls_tasks.rake
effective_polls-0.5.6 lib/tasks/effective_polls_tasks.rake
effective_polls-0.5.5 lib/tasks/effective_polls_tasks.rake
effective_polls-0.5.4 lib/tasks/effective_polls_tasks.rake
effective_polls-0.5.3 lib/tasks/effective_polls_tasks.rake
effective_polls-0.5.2 lib/tasks/effective_polls_tasks.rake
effective_polls-0.5.1 lib/tasks/effective_polls_tasks.rake
effective_polls-0.5.0 lib/tasks/effective_polls_tasks.rake
effective_polls-0.4.1 lib/tasks/effective_polls_tasks.rake
effective_polls-0.4.0 lib/tasks/effective_polls_tasks.rake