Class: AssetLink::BuilderJob
- Inherits:
-
Struct
- Object
- Struct
- AssetLink::BuilderJob
- Defined in:
- app/jobs/asset_link/builder_job.rb
Overview
An AssetLink::BuilderJob receives an array of [parent_id, child_id] and builds asset links between them
Direct Known Subclasses
Instance Attribute Summary collapse
-
#links ⇒ Object
Returns the value of attribute links.
Class Method Summary collapse
Instance Method Summary collapse
-
#perform ⇒ Object
rubocop:todo Metrics/MethodLength.
Instance Attribute Details
#links ⇒ Object
Returns the value of attribute links
5 6 7 |
# File 'app/jobs/asset_link/builder_job.rb', line 5 def links @links end |
Class Method Details
.create ⇒ Object
28 29 30 |
# File 'app/jobs/asset_link/builder_job.rb', line 28 def self.create(*) Delayed::Job.enqueue(new(*)) end |
.create_now ⇒ Object
32 33 34 |
# File 'app/jobs/asset_link/builder_job.rb', line 32 def self.create_now(*) new(*).perform end |
Instance Method Details
#perform ⇒ Object
rubocop:todo Metrics/MethodLength
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/jobs/asset_link/builder_job.rb', line 7 def perform # rubocop:todo Metrics/MethodLength # For memory reasons we need to limit transaction size to 10 links at a time transaction_count = 10 links .uniq .each_slice(transaction_count) do |link_group| ActiveRecord::Base.transaction do link_group.each do |parent, child| # Create edge can accept either a model (which it converts to an endpoint) or # an endpoint itself. Using the endpoints directly we avoid the unnecessary # database calls, but more importantly avoid the need to instantiate a load of # active record objects. parent_endpoint = Dag::Standard::EndPoint.new(parent) child_endpoint = Dag::Standard::EndPoint.new(child) AssetLink.create_edge(parent_endpoint, child_endpoint) end end end end |