Skip to content

Commit 18196a1

Browse files
committed
Handle jobs attempting to run on deleted resources
Without retrying over and over
1 parent df1e9f8 commit 18196a1

4 files changed

Lines changed: 35 additions & 13 deletions

File tree

app/workers/edit_suggestion_worker.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ def perform(arg_array)
88
logger.debug "ID: #{suggestible_id}"
99
logger.debug "TYPE: #{suggestible_type}"
1010
# Run Sidekiq task to call the BioPortal annotator
11-
suggestible = suggestible_type.constantize.find(suggestible_id)
11+
suggestible = suggestible_type.constantize.find_by_id(suggestible_id)
12+
unless suggestible
13+
logger.debug "#{suggestible_type} #{suggestible_id} not found"
14+
return
15+
end
1216
logger.debug "OBJ: #{suggestible.inspect}"
1317

1418
# Use long description if available, otherwise short.

app/workers/geocoding_worker.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@ def perform(arg_array)
1313
event_id, location = arg_array
1414
#puts "GeocodingWorker.perform(#{event_id.to_s},#{location.to_s})"
1515

16-
event = Event.find(event_id)
16+
event = Event.find_by_id(event_id)
17+
unless event
18+
logger.debug "Event #{event_id} not found"
19+
return
20+
end
1721

1822
Redis.exists_returns_integer = true
19-
redis = Redis.new
23+
redis = Redis.new(url: TeSS::Config.redis_url)
2024

2125
if redis.exists?(location)
2226
event.geocoding_cache_lookup

test/workers/edit_suggestion_worker_test.rb

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class EditSuggestionWorkerTest < ActiveSupport::TestCase
88
mock_nominatim
99
end
1010

11-
test 'Get suggestions for a material' do
11+
test 'get suggestions for a material' do
1212
material = materials(:biojs)
1313

1414
assert_nil material.edit_suggestion
@@ -27,7 +27,7 @@ class EditSuggestionWorkerTest < ActiveSupport::TestCase
2727
assert_includes material.edit_suggestion.scientific_topics.map(&:preferred_label), 'Molecular dynamics'
2828
end
2929

30-
test 'Get suggestions for an event' do
30+
test 'get suggestions for an event' do
3131
event = events(:portal_event)
3232

3333
assert_nil event.edit_suggestion
@@ -46,7 +46,7 @@ class EditSuggestionWorkerTest < ActiveSupport::TestCase
4646
assert_includes event.edit_suggestion.scientific_topics.map(&:preferred_label), 'Molecular dynamics'
4747
end
4848

49-
test 'Get suggestions for a workflow' do
49+
test 'get suggestions for a workflow' do
5050
workflow = workflows(:two)
5151

5252
assert_nil workflow.edit_suggestion
@@ -65,7 +65,7 @@ class EditSuggestionWorkerTest < ActiveSupport::TestCase
6565
assert_includes workflow.edit_suggestion.scientific_topics.map(&:preferred_label), 'Molecular dynamics'
6666
end
6767

68-
test "Don't get suggestions when description is blank" do
68+
test "don't get suggestions when description is blank" do
6969
event = events(:no_description_event)
7070

7171
assert_nil event.edit_suggestion
@@ -80,4 +80,14 @@ class EditSuggestionWorkerTest < ActiveSupport::TestCase
8080

8181
assert_nil event.edit_suggestion
8282
end
83+
84+
test 'gracefully handle getting suggestions for material that no longer exists' do
85+
Sidekiq::Testing.inline! do
86+
assert_no_difference('EditSuggestion.count') do
87+
assert_nothing_raised do
88+
EditSuggestionWorker.perform_async([Material.maximum(:id) + 1, 'Material'])
89+
end
90+
end
91+
end
92+
end
8393
end

test/workers/geocoding_worker_test.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22
require 'sidekiq/testing'
33

44
class GeocodingWorkerTest < ActiveSupport::TestCase
5-
6-
setup do
7-
end
8-
9-
test 'Get coordinates for an event' do
5+
test 'get coordinates for an event' do
106
mock_nominatim
117

128
event = events(:kilburn)
@@ -22,7 +18,7 @@ class GeocodingWorkerTest < ActiveSupport::TestCase
2218
assert_equal 0.34290, event.longitude.to_f.round(5)
2319
end
2420

25-
test 'Get coordinates for an event from cache' do
21+
test 'get coordinates for an event from cache' do
2622
event = events(:kilburn)
2723
assert_nil event.latitude
2824
assert_nil event.longitude
@@ -38,4 +34,12 @@ class GeocodingWorkerTest < ActiveSupport::TestCase
3834
assert_equal 45, event.latitude
3935
assert_equal 45, event.longitude
4036
end
37+
38+
test 'gracefully handle geocoding for event that no longer exists' do
39+
Sidekiq::Testing.inline! do
40+
assert_nothing_raised do
41+
GeocodingWorker.perform_async([Event.maximum(:id) + 1, 'Somewhere'])
42+
end
43+
end
44+
end
4145
end

0 commit comments

Comments
 (0)