Commit 9b8e7db59dcfd950d2b958ae3185d09ede6be0fc
1 parent
c05eb777
Exists in
master
and in
29 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,4 +157,22 @@ class ProfileSuggestion < ActiveRecord::Base | ||
157 | self.save | 157 | self.save |
158 | end | 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 | end | 178 | end |
config/schedule.rb
@@ -26,3 +26,7 @@ set :output, "log/cron.log" | @@ -26,3 +26,7 @@ set :output, "log/cron.log" | ||
26 | every 1.minute do | 26 | every 1.minute do |
27 | runner "SearchTerm.calculate_scores" | 27 | runner "SearchTerm.calculate_scores" |
28 | end | 28 | end |
29 | + | ||
30 | +every 90.days do | ||
31 | + runner "ProfileSuggestion.generate_all_profile_suggestions" | ||
32 | +end |
lib/profile_suggestions_job.rb
1 | class ProfileSuggestionsJob < Struct.new(:person_id) | 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 | def perform | 11 | def perform |
4 | begin | 12 | begin |
5 | person = Person.find(person_id) | 13 | person = Person.find(person_id) |