Skip to content

Commit 7198f55

Browse files
authored
Fixed bug where auto_run would only run tasks once (#5)
1 parent 9006075 commit 7198f55

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Fixed bug saving .croupier, was missing all inputs
66
* Added tests for `TaskManager.save_run`
77
* Fixed bug in inotify watcher path lookup
8+
* Fixed bug where auto_run would only run tasks once
89

910
## Version 0.3.3
1011

spec/croupier_spec.cr

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,29 @@ describe "TaskManager" do
878878
end
879879
end
880880

881+
it "should run on every modification of inputs" do
882+
with_scenario("basic") do
883+
TaskManager.auto_run(targets: ["output3"])
884+
# At this point output3 doesn't exist
885+
File.exists?("output3").should be_false
886+
# This triggers building output3
887+
File.open("input", "w") << "bar1"
888+
# The timing here is tricky, we need to wait longer
889+
# than the watch interval, but not too long because
890+
# that makes the test slow
891+
sleep 0.02.seconds
892+
File.exists?("output3").should be_true
893+
# We delete things, and then trigger another build
894+
File.delete("output3")
895+
File.delete("input")
896+
File.open("input", "w") << "bar2"
897+
Fiber.yield
898+
sleep 0.02.seconds
899+
TaskManager.auto_stop
900+
File.exists?("output3").should be_true
901+
end
902+
end
903+
881904
it "should not be triggered by deps for not specified targets" do
882905
with_scenario("basic") do
883906
TaskManager.auto_run(targets: ["output5"])

src/croupier.cr

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,6 @@ module Croupier
430430
t = tasks.fetch(output, nil)
431431
next if t.nil? || finished.includes?(t)
432432
next unless run_all || t.stale? || t.@always_run
433-
434433
Log.debug { "Running task for #{output}" }
435434
begin
436435
t.run unless dry_run
@@ -525,10 +524,13 @@ module Croupier
525524
# stop order and break the loop without running, so
526525
# we can't see the side effects without sleeping in
527526
# the tests.
528-
sleep 0.1.seconds
527+
sleep 0.01.seconds
529528
next if @queued_changes.empty?
530529
Log.info { "Detected changes in #{@queued_changes}" }
531-
self.modified += @queued_changes
530+
# Mark all targets as stale
531+
targets.each { |t| tasks[t].stale = true }
532+
@modified += @queued_changes
533+
Log.debug { "Modified: #{@modified}" }
532534
run_tasks(targets: targets)
533535
# Only clean queued changes after a successful run
534536
@queued_changes.clear
@@ -560,13 +562,16 @@ module Croupier
560562

561563
@@watcher.on_event do |event|
562564
# It's a file we care about, add it to the queue
563-
Log.debug { "Detected change in #{event.path}" }
564-
Log.trace { "Event: #{event}" }
565565
path = event.name || event.path
566+
Log.debug { "Detected change in #{path}" }
567+
Log.trace { "Event: #{event}" }
566568
@queued_changes << path.to_s if target_inputs.includes? path.to_s
567569
end
568570

569-
watch_flags = LibInotify::IN_CLOSE_WRITE | LibInotify::IN_CREATE | LibInotify::IN_MODIFY
571+
watch_flags = LibInotify::IN_DELETE |
572+
LibInotify::IN_CREATE |
573+
LibInotify::IN_MODIFY |
574+
LibInotify::IN_CLOSE
570575

571576
target_inputs.each do |input|
572577
if File.exists? input

0 commit comments

Comments
 (0)