Commit 9b8e7db59dcfd950d2b958ae3185d09ede6be0fc
1 parent
c05eb777
Exists in
master
and in
27 other branches
profile_suggestions: scheduling suggestions job
(ActionItem3234)
Showing
3 changed files
with
30 additions
and
0 deletions
Show diff stats
app/models/profile_suggestion.rb
... | ... | @@ -157,4 +157,22 @@ class ProfileSuggestion < ActiveRecord::Base |
157 | 157 | self.save |
158 | 158 | end |
159 | 159 | |
160 | + def self.generate_all_profile_suggestions | |
161 | + Delayed::Job.enqueue(ProfileSuggestion::GenerateAllJob.new) unless ProfileSuggestion::GenerateAllJob.exists? | |
162 | + end | |
163 | + | |
164 | + def self.generate_profile_suggestions(person_id) | |
165 | + Delayed::Job.enqueue ProfileSuggestionsJob.new(person_id) unless ProfileSuggestionsJob.exists?(person_id) | |
166 | + end | |
167 | + | |
168 | + class GenerateAllJob | |
169 | + def self.exists? | |
170 | + Delayed::Job.by_handler("--- !ruby/object:ProfileSuggestion::GenerateAllJob {}\n").count > 0 | |
171 | + end | |
172 | + | |
173 | + def perform | |
174 | + Person.find_each {|person| ProfileSuggestion.generate_profile_suggestions(person.id) } | |
175 | + end | |
176 | + end | |
177 | + | |
160 | 178 | end | ... | ... |
config/schedule.rb
lib/profile_suggestions_job.rb
1 | 1 | class ProfileSuggestionsJob < Struct.new(:person_id) |
2 | 2 | |
3 | + def self.exists?(person_id) | |
4 | + !find(person_id).empty? | |
5 | + end | |
6 | + | |
7 | + def self.find(person_id) | |
8 | + Delayed::Job.by_handler("--- !ruby/struct:ProfileSuggestionsJob\nperson_id: #{person_id}\n") | |
9 | + end | |
10 | + | |
3 | 11 | def perform |
4 | 12 | begin |
5 | 13 | person = Person.find(person_id) | ... | ... |