Sha256: 2ff943ff38845de592ae46bfa12be45af45877fb4eb8b03daa5411a3c4b715aa

Contents?: true

Size: 1.82 KB

Versions: 24

Compression:

Stored size: 1.82 KB

Contents

# frozen_string_literal: true

namespace :decidim_initiatives do
  desc "Check validating initiatives and moves all without changes for a configured time to discarded state"
  task check_validating: :environment do
    Decidim::Initiatives::OutdatedValidatingInitiatives
      .for(Decidim::Initiatives.max_time_in_validating_state)
      .each(&:discarded!)
  end

  desc "Check published initiatives and moves to accepted/rejected state depending on the votes collected when the signing period has finished"
  task check_published: :environment do
    Decidim::Initiatives::SupportPeriodFinishedInitiatives.new.each do |initiative|
      supports_required = initiative.scoped_type.supports_required

      if initiative.initiative_votes_count >= supports_required
        initiative.accepted!
      else
        initiative.rejected!
      end
    end
  end

  desc "Notify progress on published initiatives"
  task notify_progress: :environment do
    Decidim::Initiative
      .published
      .where.not(first_progress_notification_at: nil)
      .where(second_progress_notification_at: nil).find_each do |initiative|

      if initiative.percentage >= Decidim::Initiatives.second_notification_percentage
        notifier = Decidim::Initiatives::ProgressNotifier.new(initiative: initiative)
        notifier.notify

        initiative.second_progress_notification_at = Time.now.utc
        initiative.save
      end
    end

    Decidim::Initiative
      .published
      .where(first_progress_notification_at: nil).find_each do |initiative|

      if initiative.percentage >= Decidim::Initiatives.first_notification_percentage
        notifier = Decidim::Initiatives::ProgressNotifier.new(initiative: initiative)
        notifier.notify

        initiative.first_progress_notification_at = Time.now.utc
        initiative.save
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
decidim-initiatives-0.18.1 lib/tasks/decidim_initiatives.rake
decidim-initiatives-0.17.2 lib/tasks/decidim_initiatives.rake
decidim-initiatives-0.18.0 lib/tasks/decidim_initiatives.rake
decidim-initiatives-0.17.1 lib/tasks/decidim_initiatives.rake
decidim-initiatives-0.16.1 lib/tasks/decidim_initiatives.rake
decidim-initiatives-0.17.0 lib/tasks/decidim_initiatives.rake
decidim-initiatives-0.16.0 lib/tasks/decidim_initiatives.rake
decidim-initiatives-0.15.2 lib/tasks/decidim_initiatives.rake
decidim-initiatives-0.15.1 lib/tasks/decidim_initiatives.rake
decidim-initiatives-0.15.0 lib/tasks/decidim_initiatives.rake
decidim-initiatives-0.14.4 lib/tasks/decidim_initiatives.rake
decidim-initiatives-0.14.3 lib/tasks/decidim_initiatives.rake
decidim-initiatives-0.14.2 lib/tasks/decidim_initiatives.rake
decidim-initiatives-0.14.1 lib/tasks/decidim_initiatives.rake
decidim-initiatives-0.13.1 lib/tasks/decidim_initiatives.rake
decidim-initiatives-0.12.2 lib/tasks/decidim_initiatives.rake
decidim-initiatives-0.13.0 lib/tasks/decidim_initiatives.rake
decidim-initiatives-0.12.1 lib/tasks/decidim_initiatives.rake
decidim-initiatives-0.13.0.pre1 lib/tasks/decidim_initiatives.rake
decidim-initiatives-0.12.0 lib/tasks/decidim_initiatives.rake