Skip to content
This repository was archived by the owner on Jul 21, 2024. It is now read-only.

Commit f6377ee

Browse files
committed
Geocode users on login after sign-in
I need an example for testing background jobs, and a way to populate the new locations field on users. Create an Active Job background job for this purpose, and perform geocoding after a user has successfully signed in.
1 parent 72731f5 commit f6377ee

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

app/jobs/geocode_user_job.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class GeocodeUserJob < ApplicationJob
2+
queue_as :default
3+
4+
def perform(user)
5+
user.geocode
6+
end
7+
end

app/models/user.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ def local?
2828
["localhost", "127.0.0.1", "0.0.0.0"].include? last_sign_in_ip
2929
end
3030

31+
def after_database_authentication
32+
GeocodeUserJob.perform_later self
33+
end
34+
3135
private
3236

3337
def ensure_authentication_token

test/jobs/geocode_user_job_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require 'test_helper'
2+
3+
class GeocodeUserJobTest < ActiveJob::TestCase
4+
# test "the truth" do
5+
# assert true
6+
# end
7+
end

0 commit comments

Comments
 (0)