lib/chaotic_job/simulation.rb in chaotic_job-0.0.1 vs lib/chaotic_job/simulation.rb in chaotic_job-0.1.0

- old
+ new

@@ -4,26 +4,27 @@ # Simulation.new(job).permutations # Simulation.new(job).variants # Simulation.new(job).scenarios module ChaoticJob class Simulation - def initialize(job, test: nil, variations: 100, seed: nil, depth: 3) + def initialize(job, depth: 1, variations: 100, test: nil, seed: nil) @template = job - @test = test + @depth = depth @variations = variations + @test = test @seed = seed || Random.new_seed @random = Random.new(@seed) - @depth = depth end def run(&callback) @template.class.retry_on RetryableError, attempts: @depth + 2, wait: 1, jitter: 0 - debug "Running #{variants.size} simulations of the total #{permutations.size} possibilities..." + debug "👾 Running #{variants.size} simulations of the total #{permutations.size} possibilities..." scenarios.map do |scenario| run_scenario(scenario, &callback) + print "·" end end def permutations callstack = capture_callstack.to_a @@ -68,23 +69,23 @@ job_file_path = job_class.instance_method(:perform).source_location&.first trace = TracePoint.new(:line) do |tp| next if tp.defined_class == self.class next unless tp.path == job_file_path || - tp.defined_class == job_class + tp.defined_class == job_class @callstack << [tp.path, tp.lineno] end trace.enable { @template.dup.perform_now } @template.class.queue_adapter.enqueued_jobs = [] @callstack end def run_scenario(scenario, &callback) - debug "Running simulation with scenario: #{scenario}" + debug "👾 Running simulation with scenario: #{scenario}" @test.before_setup - scenario.enact! + scenario.run @test.after_teardown callback.call(scenario) end def clone_job_template