Class: Kaisoku::Worker
- Inherits:
-
Object
- Object
- Kaisoku::Worker
- Defined in:
- lib/kaisoku/worker.rb
Instance Method Summary collapse
-
#initialize(adapter:, collector: CoverageCollector.new, rails_integration: nil) ⇒ Worker
constructor
A new instance of Worker.
- #run(entity) ⇒ Object
Constructor Details
#initialize(adapter:, collector: CoverageCollector.new, rails_integration: nil) ⇒ Worker
Returns a new instance of Worker.
7 8 9 10 11 |
# File 'lib/kaisoku/worker.rb', line 7 def initialize(adapter:, collector: CoverageCollector.new, rails_integration: nil) @adapter = adapter @collector = collector @rails_integration = rails_integration || Rails::Integration.new(configuration: adapter.configuration) end |
Instance Method Details
#run(entity) ⇒ Object
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 39 40 41 42 43 44 |
# File 'lib/kaisoku/worker.rb', line 13 def run(entity) payload = {} collection = CoverageCollector::Result.new(dependencies: {}, skipped: true, reason: nil) @rails_integration.wrap_reloader do @adapter.run([entity], reporter: nil) do |event, lifecycle_entity, lifecycle_payload = {}| case event when :entity_started @collector.start_entity when :entity_finished collection = @collector.finish_entity payload = lifecycle_payload entity = lifecycle_entity end end end EntityResult.new( entity: entity, payload: payload, dependencies: collection.dependencies, collection_skipped: collection.skipped? ) rescue StandardError => e EntityResult.new( entity: entity, payload: { status: 'failed', duration_ms: 0 }, dependencies: {}, collection_skipped: true, error: "#{e.class}: #{e.}" ) end |