8
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
36
37
38
|
# File 'lib/riaction/profile_creator.rb', line 8
def self.perform(klass_name, id, attempt=0)
if klass_name.constantize.riactionary? &&
klass_name.constantize.riaction_profile? &&
klass_name.constantize.riaction_profile_types_defined > 0
record = klass_name.constantize.find_by_id!(id)
iactionable_api = IActionable::Api.new
record.riaction_profile_keys.each_pair do |profile_type, ids|
identifiers = ids.to_a
first_defined = identifiers.shift
iactionable_api.create_profile(profile_type.to_s, first_defined.first.to_s, first_defined.last.to_s, record.riaction_set_profile(profile_type).riaction_profile_display_name )
identifiers.each do |identifier|
iactionable_api.add_profile_identifier(profile_type.to_s, first_defined.first.to_s, first_defined.last.to_s, identifier.first.to_s, identifier.last.to_s)
end
end
else
raise ::Riaction::RuntimeError.new("#{klass_name} does not define any riaction profiles")
end
rescue ActiveRecord::RecordNotFound => e
rescue IActionable::Error::BadRequest => e
raise e
rescue IActionable::Error::Internal, Faraday::Error::TimeoutError, Timeout::Error => e
if attempt < ::Riaction::Constants.retry_attempts_for_internal_error
Resque.enqueue(self, klass_name, id, attempt+1)
else
raise e
end
end
|