Skip to content

Commit

Permalink
fix: Fix #12 where tasks didn't keep their stale status after depende…
Browse files Browse the repository at this point in the history
…ncies ran first
  • Loading branch information
ralsina committed Sep 23, 2024
1 parent ca2ed39 commit f3aebc3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
16 changes: 13 additions & 3 deletions spec/croupier_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -378,19 +378,29 @@ describe "Task" do
end
end

pending "should invalidate tasks which indirectly depend on modified files" do
it "should invalidate tasks which indirectly depend on modified files" do
with_scenario("empty") do
Task.new(id: "t1", inputs: ["input"], outputs: ["output1"]) {
t1 = Task.new(id: "t1", inputs: ["input"], outputs: ["output1"]) {
File.read("input").downcase
}
Task.new(id: "t2", inputs: ["output1"], outputs: ["output2"]) {
t2 = Task.new(id: "t2", inputs: ["output1"], outputs: ["output2"]) {
File.read("output1").upcase
}

File.write("input", "Foo")
TaskManager.run_tasks
File.read("output1").should eq "foo"
File.read("output2").should eq "FOO"
t1.stale?.should be_false
t2.stale?.should be_false
File.write("input", "Bar")
TaskManager.mark_stale_inputs
# Set to true to force recalculation
t1.stale = true
t2.stale = true
t1.stale?.should be_true
t2.stale?.should be_true

TaskManager.run_tasks
File.read("output1").should eq "bar"
File.read("output2").should eq "BAR"
Expand Down
14 changes: 8 additions & 6 deletions src/croupier.cr
Original file line number Diff line number Diff line change
Expand Up @@ -318,16 +318,18 @@ module Croupier
)
mark_stale_inputs
finished = Set(Task).new
outputs.each do |output|
t = tasks.fetch(output, nil)
outputs.compact_map { |o|
tasks.fetch(o, nil)
}.reject { |t|
!(t.stale? || run_all || t.@always_run)
}.each do |t|
next if t.nil? || finished.includes?(t)
next unless run_all || t.stale? || t.@always_run
Log.debug { "Running task for #{output}" }
raise "Can't run task for #{output}: Waiting for #{t.waiting_for}" unless t.ready?(run_all) || dry_run
Log.debug { "Running task for #{t.outputs}" }
raise "Can't run task for #{t.outputs}: Waiting for #{t.waiting_for}" unless t.waiting_for.empty? || dry_run
begin
t.run unless dry_run
rescue ex
Log.error { "Error running task for #{output}: #{ex}" }
Log.error { "Error running task for #{t.outputs}: #{ex}" }
raise ex unless keep_going
end
finished << t
Expand Down
2 changes: 2 additions & 0 deletions src/task.cr
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ module Croupier
(modified_inputs = inputs.any? { |input| TaskManager.modified.includes? input }) ||
(stale_inputs = @inputs.any? { |input| TaskManager.tasks.has_key?(input) && TaskManager.tasks[input].stale? })

# pp! id, @inputs.map { |input| {input, TaskManager.tasks.has_key?(input), TaskManager.tasks.has_key?(input) && TaskManager.tasks[input].stale?}}

if result
Log.trace {
"#{outputs} is stale because of missing_file_outputs"
Expand Down

0 comments on commit f3aebc3

Please sign in to comment.