OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
differentiate between scheduled_at and cron_at
ulferts2d5420a424ee
diff --git a/app/workers/notifications/schedule_date_alerts_notifications_job.rb b/app/workers/notifications/schedule_date_alerts_notifications_job.rbindex a744e300078..75c1811a1a0 100644--- a/app/workers/notifications/schedule_date_alerts_notifications_job.rb+++ b/app/workers/notifications/schedule_date_alerts_notifications_job.rb@@ -50,17 +50,17 @@ module Notifications# between scheduled time and current time need to be considered to match# with 1:00am in a time zone.def times_from_scheduled_to_execution- time = scheduled_time- times = []- begin- times << time- time += 15.minutes- end while time < Time.current- times+ (scheduled_time.to_i..Time.current.to_i)+ .step(15.minutes)+ .map do |time|+ Time.zone.at(time)+ endenddef scheduled_time- job_scheduled_at.then { |t| t.change(min: t.min / 15 * 15) }+ GoodJob::Job+ .find(job_id)+ .cron_atendendenddiff --git a/spec/workers/notifications/schedule_date_alerts_notifications_job_spec.rb b/spec/workers/notifications/schedule_date_alerts_notifications_job_spec.rbindex 5e9fcc86917..232f2e37345 100644--- a/spec/workers/notifications/schedule_date_alerts_notifications_job_spec.rb+++ b/spec/workers/notifications/schedule_date_alerts_notifications_job_spec.rb@@ -54,8 +54,17 @@ RSpec.describe Notifications::ScheduleDateAlertsNotificationsJob, type: :job, wischeduled_jobend- def set_scheduled_time(scheduled_at)- GoodJob::Job.where(id: scheduled_job.job_id).update_all(scheduled_at:)+ def set_cron_time(cron_at)+ GoodJob::Job+ .where(id: scheduled_job.job_id)+ .update_all(cron_at:,+ scheduled_at: cron_at)+ end++ def set_scheduled_at_time(scheduled_at)+ GoodJob::Job+ .where(id: scheduled_job.job_id)+ .update_all(scheduled_at:)end# Converts "hh:mm" into { hour: h, min: m }@@ -67,11 +76,12 @@ RSpec.describe Notifications::ScheduleDateAlertsNotificationsJob, type: :job, witimezone.now.change(time_hash(time))end- def run_job(scheduled_at:, local_time:, timezone:)- set_scheduled_time(timezone_time(scheduled_at, timezone))+ def run_job(cron_at:, local_time:, timezone:, scheduled_at: cron_at)+ set_cron_time(timezone_time(cron_at, timezone))+ set_scheduled_at_time(timezone_time(scheduled_at, timezone))+travel_to(timezone_time(local_time, timezone)) doGoodJob.perform_inline- # scheduled_job.reload.invoke_jobyield if block_given?end@@ -96,7 +106,10 @@ RSpec.describe Notifications::ScheduleDateAlertsNotificationsJob, type: :job, wiit "creates the job for the user" doexpect do- run_job(timezone:, scheduled_at:, local_time:) do+ run_job(timezone:,+ cron_at:,+ scheduled_at: defined?(scheduled_at) ? scheduled_at : cron_at,+ local_time:) doj = GoodJob::Job.where(job_class:).order(created_at: :desc).last@@ -109,7 +122,10 @@ RSpec.describe Notifications::ScheduleDateAlertsNotificationsJob, type: :job, wishared_examples_for "job execution creates no date alerts creation job" doit "creates no job" doexpect do- run_job(timezone:, scheduled_at:, local_time:)+ run_job(timezone:,+ cron_at:,+ scheduled_at: defined?(scheduled_at) ? scheduled_at : cron_at,+ local_time:)end.not_to change(GoodJob::Job, :count)endend@@ -118,7 +134,7 @@ RSpec.describe Notifications::ScheduleDateAlertsNotificationsJob, type: :job, wicontext "for users whose local time is 1:00 am (UTC+1) when the job is executed" doit_behaves_like "job execution creates date alerts creation job" dolet(:timezone) { timezone_paris }- let(:scheduled_at) { "1:00" }+ let(:cron_at) { "1:00" }let(:local_time) { "1:04" }let(:user) { user_paris }end@@ -127,7 +143,7 @@ RSpec.describe Notifications::ScheduleDateAlertsNotificationsJob, type: :job, wicontext "for users whose local time is 1:00 am (UTC+05:45) when the job is executed" doit_behaves_like "job execution creates date alerts creation job" dolet(:timezone) { timezone_kathmandu }- let(:scheduled_at) { "1:00" }+ let(:cron_at) { "1:00" }let(:local_time) { "1:04" }let(:user) { user_kathmandu }end@@ -136,46 +152,59 @@ RSpec.describe Notifications::ScheduleDateAlertsNotificationsJob, type: :job, wicontext "without enterprise token", with_ee: false doit_behaves_like "job execution creates no date alerts creation job" dolet(:timezone) { timezone_paris }- let(:scheduled_at) { "1:00" }+ let(:cron_at) { "1:00" }let(:local_time) { "1:04" }endend- context "when scheduled and executed at 01:00 am local time" do+ context "when cron-ed, scheduled and executed at 01:00 am local time" doit_behaves_like "job execution creates date alerts creation job" dolet(:timezone) { timezone_paris }- let(:scheduled_at) { "1:00" }+ let(:cron_at) { "1:00" }let(:local_time) { "1:00" }let(:user) { user_paris }endend- context "when scheduled and executed at 01:14 am local time" do+ context "when cron-ed at 1:00 am but scheduled and executed at 01:14 am local time" doit_behaves_like "job execution creates date alerts creation job" dolet(:timezone) { timezone_paris }+ let(:cron_at) { "1:00" }let(:scheduled_at) { "1:14" }let(:local_time) { "1:14" }let(:user) { user_paris }endend- context "when scheduled and executed at 01:15 am local time" do+ context "when cron-ed, scheduled and executed at 01:15 am local time" doit_behaves_like "job execution creates no date alerts creation job" dolet(:timezone) { timezone_paris }+ let(:cron_at) { "1:15" }let(:scheduled_at) { "1:15" }let(:local_time) { "1:15" }endend- context "when scheduled at 01:00 am local time and executed at 01:37 am local time" do+ context "when cron-ed and scheduled at 01:00 am local time and executed at 01:37 am local time" doit_behaves_like "job execution creates date alerts creation job" dolet(:timezone) { timezone_paris }+ let(:cron_at) { "1:00" }let(:scheduled_at) { "1:00" }let(:local_time) { "1:37" }let(:user) { user_paris }endend+ context "when cron-ed at 01:00 am but rescheduled to 1:15 and executed at 01:37 am local time" do+ it_behaves_like "job execution creates date alerts creation job" do+ let(:timezone) { timezone_paris }+ let(:cron_at) { "1:00" }+ let(:scheduled_at) { "1:15" }+ let(:local_time) { "1:37" }+ let(:user) { user_paris }+ end+ end+context "with a user having only due_date active in notification settings" dobefore doNotificationSetting@@ -187,7 +216,7 @@ RSpec.describe Notifications::ScheduleDateAlertsNotificationsJob, type: :job, wiit_behaves_like "job execution creates date alerts creation job" dolet(:timezone) { timezone_paris }- let(:scheduled_at) { "1:00" }+ let(:cron_at) { "1:00" }let(:local_time) { "1:00" }let(:user) { user_paris }end@@ -204,7 +233,7 @@ RSpec.describe Notifications::ScheduleDateAlertsNotificationsJob, type: :job, wiit_behaves_like "job execution creates date alerts creation job" dolet(:timezone) { timezone_paris }- let(:scheduled_at) { "1:00" }+ let(:cron_at) { "1:00" }let(:local_time) { "1:00" }let(:user) { user_paris }end@@ -221,7 +250,7 @@ RSpec.describe Notifications::ScheduleDateAlertsNotificationsJob, type: :job, wiit_behaves_like "job execution creates date alerts creation job" dolet(:timezone) { timezone_paris }- let(:scheduled_at) { "1:00" }+ let(:cron_at) { "1:00" }let(:local_time) { "1:00" }let(:user) { user_paris }end@@ -238,7 +267,7 @@ RSpec.describe Notifications::ScheduleDateAlertsNotificationsJob, type: :job, wiit_behaves_like "job execution creates no date alerts creation job" dolet(:timezone) { timezone_paris }- let(:scheduled_at) { "1:00" }+ let(:cron_at) { "1:00" }let(:local_time) { "1:00" }endend@@ -261,7 +290,7 @@ RSpec.describe Notifications::ScheduleDateAlertsNotificationsJob, type: :job, wiit_behaves_like "job execution creates date alerts creation job" dolet(:timezone) { timezone_paris }- let(:scheduled_at) { "1:00" }+ let(:cron_at) { "1:00" }let(:local_time) { "1:00" }let(:user) { user_paris }end@@ -274,7 +303,7 @@ RSpec.describe Notifications::ScheduleDateAlertsNotificationsJob, type: :job, wiit_behaves_like "job execution creates no date alerts creation job" dolet(:timezone) { timezone_paris }- let(:scheduled_at) { "1:00" }+ let(:cron_at) { "1:00" }let(:local_time) { "1:00" }endend