Class: ReverseMatchJob
- Inherits:
-
Struct
- Object
- Struct
- ReverseMatchJob
- Defined in:
- app/jobs/reverse_match_job.rb
Instance Attribute Summary collapse
-
#concept ⇒ Object
Returns the value of attribute concept.
-
#match_class ⇒ Object
Returns the value of attribute match_class.
-
#object ⇒ Object
Returns the value of attribute object.
-
#referer ⇒ Object
Returns the value of attribute referer.
-
#subject ⇒ Object
Returns the value of attribute subject.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
Instance Attribute Details
#concept ⇒ Object
Returns the value of attribute concept
1 2 3 |
# File 'app/jobs/reverse_match_job.rb', line 1 def concept @concept end |
#match_class ⇒ Object
Returns the value of attribute match_class
1 2 3 |
# File 'app/jobs/reverse_match_job.rb', line 1 def match_class @match_class end |
#object ⇒ Object
Returns the value of attribute object
1 2 3 |
# File 'app/jobs/reverse_match_job.rb', line 1 def object @object end |
#referer ⇒ Object
Returns the value of attribute referer
1 2 3 |
# File 'app/jobs/reverse_match_job.rb', line 1 def referer @referer end |
#subject ⇒ Object
Returns the value of attribute subject
1 2 3 |
# File 'app/jobs/reverse_match_job.rb', line 1 def subject @subject end |
#type ⇒ Object
Returns the value of attribute type
1 2 3 |
# File 'app/jobs/reverse_match_job.rb', line 1 def type @type end |
Instance Method Details
#enqueue(job) ⇒ Object
2 3 4 5 6 7 |
# File 'app/jobs/reverse_match_job.rb', line 2 def enqueue(job) job.delayed_reference_id = concept.id job.delayed_reference_type = concept.class.to_s job.delayed_global_reference_id = concept.to_global_id job.save! end |
#error(job, exception) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/jobs/reverse_match_job.rb', line 37 def error(job, exception) error_type = nil case exception when Faraday::ConnectionFailed if exception&.wrapped_exception.class == Net::OpenTimeout error_type = 'timeout_error' else error_type = 'connection_failed' end when Faraday::TimeoutError error_type = 'timeout_error' when Faraday::ResourceNotFound error_type = 'resource_not_found' when Faraday::ClientError body = exception.response[:body] || {} = JSON.parse(body) unless body.empty? error_type = ['type'] else error_type = exception. end unless error_type.nil? job. = error_type job.save! end end |
#perform ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/jobs/reverse_match_job.rb', line 9 def perform if concept.unpublished? raise MatchedConceptUnpublished, "concept_not_published_yet" end conn = connection(subject, { accept: 'application/json' }) response = conn.get link = response.body['links'].detect { |h| h['rel'] == type.to_s } request_url = link['href'] request_method = link['method'] conn = connection(request_url, { content_type: 'application/json', referer: referer }) begin response = conn.send(request_method) do |req| req.params['match_class'] = match_class req.params['uri'] = object end rescue Faraday::ClientError => e # do not catch Mapping-Exists errors, just keep job running and do nothing # except delete job if e.response.nil? || e.response[:status] != 409 raise e end end end |