0

In our application, we have user, tracked locations of users and locations can be filtered with some applied filters.

In user.rb

class User

  has_many :tracked_locations

end

In tracked_locations.rb

class TrackedLocations

  belongs_to :user

end

In filtered_locations.rb

class FilteredLocations

  has_many :tracked_locations

end

Our one of the background job will group the tracked_locations of the user based on the applied filter of filtered_locations.

class FilteredLocationsJob < ApplicationJob

# I need to collect the user ids based on some logic before the
# location association happens - This may be large data. There may be
# variable number of data set(user_ids array) that I need to collect 
# from here based on some created filters.


def perform(params)
  ActiveRecord::Base.transaction do 
    # Logic to associate data
  end
end

# I will compare the user ids which were collected before this 
# transaction happened and do some logics here.

end

In conclusion, I need to collect some data before a transaction and use it for comparing after the transaction completed. The data which I need will based on the created filters (say if I created 10 filters means, I need to collect user_ids array for all the 10 filters, I will compare the 10 array values and exclude those users for further processing).

How to save and handle the data here in my requirement. Kindly let me know if any clarification needed.

Duke
  • 3,226
  • 1
  • 18
  • 23
Aarthi
  • 1,451
  • 15
  • 39
  • Doesn't `before_save` work? https://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html – rj487 Jul 09 '19 at 18:58
  • So what are you asking? How to trigger a background-job immediately and wait for it? If this is a good approach? What is the context: is this inside a controller (is a user actively waiting) or is this a script/job? – nathanvda Feb 08 '20 at 15:06

0 Answers0