From 2d3b2283af13269d2c9828b74d25f84c4df72c36 Mon Sep 17 00:00:00 2001 From: Max Wofford Date: Mon, 12 May 2025 14:58:55 -0400 Subject: [PATCH] Suspend sailors log poll for users with active migrations (#221) --- app/jobs/sailors_log_poll_for_changes_job.rb | 3 +++ app/models/user.rb | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/app/jobs/sailors_log_poll_for_changes_job.rb b/app/jobs/sailors_log_poll_for_changes_job.rb index 97658a8..560c382 100644 --- a/app/jobs/sailors_log_poll_for_changes_job.rb +++ b/app/jobs/sailors_log_poll_for_changes_job.rb @@ -30,6 +30,9 @@ class SailorsLogPollForChangesJob < ApplicationJob private def update_sailors_log(sailors_log) + # Skip if there's an active migration job for this user + return [] if sailors_log.user.in_progress_migration_jobs? + project_updates = [] project_durations = Heartbeat.where(user_id: sailors_log.user.id) .group(:project).duration_seconds diff --git a/app/models/user.rb b/app/models/user.rb index 603bf1e..db6f3c6 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -67,6 +67,13 @@ class User < ApplicationRecord ).order(created_at: :desc).limit(10).all end + def in_progress_migration_jobs? + GoodJob::Job.where(job_class: "MigrateUserFromHackatimeJob") + .where("serialized_params->>'arguments' = ?", [ id ].to_json) + .where(finished_at: nil) + .exists? + end + def set_neighborhood_channel return unless slack_uid.present?