Merge pull request #36 from hackclub/automatic-migration

Automatically migrate user data on signin
This commit is contained in:
Max Wofford
2025-03-12 13:36:14 -04:00
committed by GitHub
3 changed files with 15 additions and 5 deletions

View File

@@ -20,6 +20,12 @@ class SessionsController < ApplicationController
if @user&.persisted?
session[:user_id] = @user.id
if @user.data_migration_jobs.empty?
# if they don't have a data migration job, add one to the queue
OneTime::MigrateUserFromHackatimeJob.perform_later(@user.id)
end
redirect_to root_path, notice: "Successfully signed in with Slack!"
else
Rails.logger.error "Failed to create/update user from Slack data"

View File

@@ -11,11 +11,7 @@ class UsersController < ApplicationController
enabled: true,
).where.not(slack_channel_id: "C0835AZP9GB")
@heartbeats_migration_jobs = GoodJob::Job.where(
"serialized_params->>'arguments' LIKE ?", "%#{@user.id}%"
).where(
"job_class = ?", "OneTime::MigrateUserFromHackatimeJob"
).order(created_at: :desc).limit(10).all
@heartbeats_migration_jobs = @user.data_migration_jobs
end
def update

View File

@@ -28,6 +28,14 @@ class User < ApplicationRecord
compliment_text: 2
}
def data_migration_jobs
GoodJob::Job.where(
"serialized_params->>'arguments' LIKE ?", "%#{id}%"
).where(
"job_class = ?", "OneTime::MigrateUserFromHackatimeJob"
).order(created_at: :desc).limit(10).all
end
def format_extension_text(duration)
case hackatime_extension_text_type
when "simple_text"