From 2bb009fa0b627aab8eaed9857727278223967c12 Mon Sep 17 00:00:00 2001
From: Teal <git@teal.is>
Date: Mon, 27 May 2024 16:22:55 +0200
Subject: [PATCH] fucking hell

---
 Gemfile                                          |  2 +-
 Gemfile.lock                                     | 12 ++++++++----
 app/jobs/telegram_group_chat_notification_job.rb |  1 +
 app/jobs/telegram_notify_upcoming_job.rb         |  7 +++++--
 config/cronotab.rb                               |  4 ++--
 5 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/Gemfile b/Gemfile
index 273814f..dd5c3e3 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 5bcb70d..93278da 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 87bd0fd..e588bd9 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 3c77039..b2191b0 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 3fd28bc..c738d9d 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
-- 
GitLab