File tree 2 files changed +10
-5
lines changed
2 files changed +10
-5
lines changed Original file line number Diff line number Diff line change 1
1
class SearchSyncJob
2
2
include Sidekiq ::Worker
3
+ sidekiq_options queue : :search_sync
3
4
4
- sidekiq_options queue : :medium
5
-
5
+ # TODO refactor this, when we drop Tire.
6
6
def perform
7
+ return if duplicate_job? # Skip if there is more enqueued jobs
8
+
7
9
number_of_protips_in_index = Protip . tire . search { query { all } } . total
8
10
number_of_protips_in_database = Protip . count
9
11
@@ -13,7 +15,7 @@ def perform
13
15
query { all }
14
16
end . map { |protip | protip . id . to_i }
15
17
16
- protips_in_database = Protip . select ( :id ) . map ( & :id )
18
+ protips_in_database = Protip . pluck ( :id )
17
19
18
20
#now that we know the sets in db and index, calculate the missing records
19
21
nonexistent_protips = ( protips_in_index - protips_in_database )
@@ -26,8 +28,10 @@ def perform
26
28
unindexed_protips . each do |unindexed_protip_id |
27
29
IndexProtipJob . perform_async ( unindexed_protip_id )
28
30
end
29
-
30
- puts "removed #{ nonexistent_protips . count } protips and added #{ unindexed_protips . count } protips"
31
31
end
32
32
end
33
+
34
+ def duplicate_job?
35
+ Sidekiq ::Queue . new ( 'search_sync' ) . size > 2
36
+ end
33
37
end
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ production:
7
7
:queues :
8
8
- [low, 1]
9
9
- [default, 2]
10
+ - [search_sync, 2]
10
11
- [medium, 3]
11
12
- [high, 4]
12
13
- [urgent, 5]
You can’t perform that action at this time.
0 commit comments