Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sending notification digest & rails log_level to warn #74

Merged
merged 9 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env-example
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ BACKUP_S3RETENTION_ENABLED=
DECIDIM_SESSION_TIMEOUT=

# SKIP_FIRST_LOGIN_AUTHORIZATION=true
# RAILS_LOG_LEVEL=warn
6 changes: 3 additions & 3 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ env:
NODE_VERSION: 16.9.1
RUBYOPT: '-W:no-deprecated'
# Set locales available for i18n tasks
ENFORCED_LOCALES: "en,fr"
AVAILABLE_LOCALES: "en,fr"
ENFORCED_LOCALES: "en,fr,ca,es"
AVAILABLE_LOCALES: "en,fr,ca,es"

jobs:
todo:
Expand Down Expand Up @@ -254,4 +254,4 @@ jobs:
namespace: ${{ vars.REGISTRY_NAMESPACE }}
password: ${{ secrets.TOKEN }}
image_name: ${{ vars.IMAGE_NAME }}
tag: ${{ steps.tag_version.outputs.new_tag }}
tag: ${{ steps.tag_version.outputs.new_tag }}
4 changes: 2 additions & 2 deletions Dockerfile.local
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ RUN yarn install --frozen-lock
COPY . .

RUN bundle exec bootsnap precompile --gemfile app/ lib/ config/ bin/ db/ && \
bundle exec rails deface:precompile && \
bundle exec rails assets:precompile
bundle exec rails assets:precompile && \
bundle exec rails deface:precompile

run mkdir certificate-https-local
RUN openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 -subj "/C=FR/ST=France/L=Paris/O=decidim/CN=decidim.eu" -keyout ./certificate-https-local/key.pem -out ./certificate-https-local/cert.pem;
Expand Down
26 changes: 13 additions & 13 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ GIT

GIT
remote: https://github.com/OpenSourcePolitics/decidim-module-slider
revision: cf5632125da12749589ec321f3112e51dfd3a589
revision: 776378746abd5a637d654fbe068ca98f5bde2371
branch: rc/0.27
specs:
decidim-slider (0.0.3)
Expand Down Expand Up @@ -129,7 +129,7 @@ GEM
public_suffix (>= 2.0.2, < 6.0)
ast (2.4.2)
aws-eventstream (1.3.0)
aws-partitions (1.901.0)
aws-partitions (1.905.0)
aws-sdk-core (3.191.5)
aws-eventstream (~> 1, >= 1.3.0)
aws-partitions (~> 1, >= 1.651.0)
Expand All @@ -138,13 +138,13 @@ GEM
aws-sdk-kms (1.78.0)
aws-sdk-core (~> 3, >= 3.191.0)
aws-sigv4 (~> 1.1)
aws-sdk-s3 (1.146.0)
aws-sdk-s3 (1.146.1)
aws-sdk-core (~> 3, >= 3.191.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.8)
aws-sigv4 (1.8.0)
aws-eventstream (~> 1, >= 1.0.2)
axe-core-api (4.8.2)
axe-core-api (4.9.0)
dumb_delegator
virtus
axe-core-rspec (4.1.0)
Expand Down Expand Up @@ -566,8 +566,8 @@ GEM
kramdown (~> 2.0)
launchy (2.5.2)
addressable (~> 2.8)
letter_opener (1.9.0)
launchy (>= 2.2, < 3)
letter_opener (1.10.0)
launchy (>= 2.2, < 4)
letter_opener_web (1.4.1)
actionmailer (>= 3.2)
letter_opener (~> 1.0)
Expand Down Expand Up @@ -647,11 +647,11 @@ GEM
rack-protection
omniauth-facebook (5.0.0)
omniauth-oauth2 (~> 1.2)
omniauth-google-oauth2 (1.1.1)
omniauth-google-oauth2 (1.1.2)
jwt (>= 2.0)
oauth2 (~> 2.0.6)
oauth2 (~> 2.0)
omniauth (~> 2.0)
omniauth-oauth2 (~> 1.8.0)
omniauth-oauth2 (~> 1.8)
omniauth-oauth (1.2.0)
oauth
omniauth (>= 1.0, < 3)
Expand Down Expand Up @@ -687,7 +687,7 @@ GEM
actionmailer (>= 3)
net-smtp
premailer (~> 1.7, >= 1.7.9)
public_suffix (5.0.4)
public_suffix (5.0.5)
puma (5.6.8)
nio4r (~> 2.0)
raabro (1.4.0)
Expand Down Expand Up @@ -739,7 +739,7 @@ GEM
rake (>= 12.2)
thor (~> 1.0)
rainbow (3.1.1)
rake (13.1.0)
rake (13.2.0)
ransack (2.4.2)
activerecord (>= 5.2.4)
activesupport (>= 5.2.4)
Expand Down Expand Up @@ -817,7 +817,7 @@ GEM
ruby-progressbar (1.13.0)
ruby-vips (2.2.1)
ffi (~> 1.12)
rubyXL (3.4.25)
rubyXL (3.4.26)
nokogiri (>= 1.10.8)
rubyzip (>= 1.3.0)
ruby_http_client (3.5.5)
Expand Down Expand Up @@ -1000,4 +1000,4 @@ RUBY VERSION
ruby 3.0.6p216

BUNDLED WITH
2.2.33
2.4.9
11 changes: 11 additions & 0 deletions app/jobs/notifications_digest_mail_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

require "decidim/notifications_digest"

class NotificationsDigestMailJob < ApplicationJob
queue_as :scheduled

def perform(frequency)
Decidim::NotificationsDigest.notifications_digest(frequency.to_sym)
end
end
3 changes: 2 additions & 1 deletion config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@

# Use the lowest log level to ensure availability of diagnostic information
# when problems arise.
config.log_level = :info
# The available log levels are: :debug, :info, :warn, :error, :fatal, and :unknown
config.log_level = ENV.fetch("RAILS_LOG_LEVEL", "warn").to_sym

# Prepend all log lines with the following tags.
config.log_tags = [:request_id]
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/decidim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
config.mailer_sender = "OSP Agora <[email protected]>"

config.default_locale = ENV.fetch("DEFAULT_LOCALE", "en").to_sym
config.available_locales = ENV.fetch("AVAILABLE_LOCALES", "en,fr").split(",").map(&:to_sym)
config.available_locales = ENV.fetch("AVAILABLE_LOCALES", "en,fr,ca,es").split(",").map(&:to_sym)

# Timeout session
config.expire_session_after = ENV.fetch("DECIDIM_SESSION_TIMEOUT", 180).to_i.minutes
Expand Down
4 changes: 2 additions & 2 deletions config/initializers/health_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
# sensitive information
config.include_error_in_response_body = false

# Log level (success or failure message with error details is sent to rails log unless this is set to nil)
config.log_level = "info"
# The available log levels are: :debug, :info, :warn, :error, :fatal, and :unknown
config.log_level = ENV.fetch("RAILS_LOG_LEVEL", "warn").to_sym

# Timeout in seconds used when checking smtp server
config.smtp_timeout = 30.0
Expand Down
11 changes: 11 additions & 0 deletions config/sidekiq.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
:concurrency: 5
:max_retries: 5
:queues:
- default
- backups
Expand Down Expand Up @@ -27,3 +28,13 @@
cron: '0 0 4 * * *' # Run at 04:00
class: BackupJob
queue: backups
SendNotificationMailDaily:
cron: '0 0 7 * * *' # Run at 07:00AM every days
class: NotificationsDigestMailJob
queue: mailers
args: :daily
SendNotificationMailWeekly:
cron: '0 0 8 * * 2' # Run at 08:00AM on Tuesday
class: NotificationsDigestMailJob
queue: mailers
args: :weekly
14 changes: 14 additions & 0 deletions lib/decidim/notifications_digest.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module Decidim
module NotificationsDigest
def self.notifications_digest(frequency)
return unless [:daily, :weekly].include?(frequency)

time = Time.now.utc
Decidim::User.where(notifications_sending_frequency: frequency).find_each do |user|
Decidim::EmailNotificationsDigestGeneratorJob.perform_later(user.id, frequency, time: time)
end
end
end
end
2 changes: 1 addition & 1 deletion spec/i18n_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

describe "I18n sanity" do
let(:locales) do
ENV["ENFORCED_LOCALES"].presence || "en,fr"
"en,fr"
end

let(:i18n) { I18n::Tasks::BaseTask.new(locales: locales.split(",")) }
Expand Down
15 changes: 15 additions & 0 deletions spec/jobs/notifications_digest_mail_job_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

require "spec_helper"

describe NotificationsDigestMailJob, type: :job do
describe "#perform" do
[:daily, :weekly].each do |frequency|
it "calls notifications digest with #{frequency}" do
expect(Decidim::NotificationsDigest).to receive(:notifications_digest).with(frequency)

subject.perform(frequency)
end
end
end
end
44 changes: 44 additions & 0 deletions spec/lib/decidim/notifications_digest_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# frozen_string_literal: true

require "spec_helper"
require "decidim/notifications_digest"

describe Decidim::NotificationsDigest do
describe "#notifications_digest" do
subject { described_class.notifications_digest(frequency) }

let(:frequency) { :daily }
let!(:users_daily) { create_list :user, 4, notifications_sending_frequency: :daily }
let!(:users_weekly) { create_list :user, 2, notifications_sending_frequency: :weekly }

before do
allow(Decidim::EmailNotificationsDigestGeneratorJob).to receive(:perform_later).and_return(true)
end

it "executes DigestGeneratorJob on daily users" do
subject

expect(Decidim::EmailNotificationsDigestGeneratorJob).to have_received(:perform_later).exactly(4)
end

context "and frequency is weekly" do
let(:frequency) { :weekly }

it "executes DigestGeneratorJob on weekly users" do
subject

expect(Decidim::EmailNotificationsDigestGeneratorJob).to have_received(:perform_later).exactly(2)
end
end

context "and frequency is not in list" do
let(:frequency) { :unknown }

it "executes DigestGeneratorJob on weekly users" do
subject

expect(Decidim::EmailNotificationsDigestGeneratorJob).not_to have_received(:perform_later)
end
end
end
end
2 changes: 1 addition & 1 deletion spec/lib/decidim_app/k8s/organization_exporter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
it "returns the organization columns" do
expect(subject.organization_columns).to eq({
"available_authorizations" => [],
"available_locales" => %w(en fr),
"available_locales" => %w(en fr ca es),
"default_locale" => "en",
"file_upload_settings" => {
"allowed_content_types" => {
Expand Down
Loading
Loading