diff --git a/Gemfile b/Gemfile index 273814f0c0d2e9d2142fce5df00618e9af50813d..dd5c3e3cde6ab5482e534177a2d21edeccd4c4a1 100644 --- a/Gemfile +++ b/Gemfile @@ -70,6 +70,6 @@ gem "icalendar", "~> 2.10" gem "telegram-bot-ruby", "~> 2.0" -gem "crono", "~> 2.0" +gem "crono", git: 'https://github.com/plashchynski/crono' #"~> 2.0" gem "daemons", "~> 1.4" diff --git a/Gemfile.lock b/Gemfile.lock index 5bcb70da050cad0b87879c4c5fa3299cf8666ab0..93278da586e20f34621e19797402d37f3ec27277 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,10 @@ +GIT + remote: https://github.com/plashchynski/crono + revision: 6bf1ec9cfd383265e5578e29c2a6cd706476ab91 + specs: + crono (2.0.1) + rails (>= 5.2.8) + GEM remote: https://rubygems.org/ specs: @@ -96,9 +103,6 @@ GEM concurrent-ruby (1.2.3) connection_pool (2.4.1) crass (1.0.6) - crono (2.0.1) - rails (>= 5.2.8) - sprockets-rails daemons (1.4.1) date (3.3.4) debug (1.9.2) @@ -323,7 +327,7 @@ DEPENDENCIES bcrypt (~> 3.1.7) bootsnap capybara - crono (~> 2.0) + crono! daemons (~> 1.4) debug hotwire-rails (~> 0.1.3) diff --git a/app/jobs/telegram_group_chat_notification_job.rb b/app/jobs/telegram_group_chat_notification_job.rb index 87bd0fd17d2155f01e5d3105aedea2c3705be47e..e588bd97dc7e305a4f035002b629db97a968c09b 100644 --- a/app/jobs/telegram_group_chat_notification_job.rb +++ b/app/jobs/telegram_group_chat_notification_job.rb @@ -5,6 +5,7 @@ class TelegramGroupChatNotificationJob < NotificationJob def perform(**args) channel = NotificationChannel.find_by(name: 'telegram_group_chat') + Rails.logger.debug("TelegramGroupChatNotificationJob #{args.inspect}") return unless channel&.data token = channel.data['token'] return unless token diff --git a/app/jobs/telegram_notify_upcoming_job.rb b/app/jobs/telegram_notify_upcoming_job.rb index 3c77039abfc16de673d8aaf36965e605d9808d99..b2191b064c041c1a5947d17a7236b3a477075f93 100644 --- a/app/jobs/telegram_notify_upcoming_job.rb +++ b/app/jobs/telegram_notify_upcoming_job.rb @@ -1,8 +1,11 @@ class TelegramNotifyUpcomingJob < ApplicationJob queue_as :default - def perform(**args) - Session.scheduled.includes(:stage, :assignments).where(stage: { name: ["Stage 1", "Stage 2", "Standby"] }).where(starts_at: (Time.now + args[:offset])..(Time.now + args[:offset] + args[:interval])).order(:starts_at).each do |session| + def perform(args) + offset = args["offset"] + interval = args["interval"] + Session.scheduled.includes(:stage, :assignments).where(stage: { name: ["Stage 1", "Stage 2", "Standby"] }).where(starts_at: (Time.now + offset)..(Time.now + offset + interval)).order(:starts_at).each do |session| + puts session.inspect assignees = session.assignments.map(&:user) if assignees.length.positive? notify_names = assignees.map { |a| a.telegram_username ? "@#{a.telegram_username}" : a.name } diff --git a/config/cronotab.rb b/config/cronotab.rb index 3fd28bcddabc0e88354b968f2aee3d2040bfb051..c738d9df24b5b15857502a5f9021fe694d4047ec 100644 --- a/config/cronotab.rb +++ b/config/cronotab.rb @@ -14,5 +14,5 @@ # Crono.perform(TestJob).every 2.days, at: '15:30' # -Crono.perform(FetchConferenceDataJob, 'rp2024').every 5.minutes -Crono.perform(TelegramNotifyUpcomingJob, {offset: 15.minutes, interval: 1.minute}).every 1.minute +# Crono.perform(FetchConferenceDataJob, 'rp2024').every 5.minutes +Crono.perform(TelegramNotifyUpcomingJob, { offset: 15.minutes.to_i, interval: 1.minute.to_i }).every 1.minute