Skip to content

Commit

Permalink
Merge branch 'main' of github.com:ralsina/croupier
Browse files Browse the repository at this point in the history
  • Loading branch information
ralsina committed Jun 21, 2023
2 parents fe7523b + b7f5639 commit 7b81dea
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ jobs:
shards install
crystal build src/run_tests.cr
kcov --clean --include-path=./src coverage ./run_tests
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
curl -Os https://uploader.codecov.io/latest/linux/codecov
chmod +x codecov
./codecov -t ${CODECOV_TOKEN} -s coverage
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
/shard.lock
.croupier
/coverage/
/spec/files/
/spec/testcases/input*
/spec/testcases/output*
3 changes: 1 addition & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
* Fix bug that triggered too many builds in some cases in
[nicolino](https://github.com/ralsina/nicolino)
* Bring the parallel runner up to date with the serial one,
including equivalent tests (failing with the `always_run`
flag for now)
including equivalent tests

## Version 0.2.0

Expand Down
30 changes: 16 additions & 14 deletions src/croupier.cr
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ module Croupier
proc : TaskProc | Nil = nil,
no_save : Bool = false,
id : String | Nil = nil,
always_run : Bool = false,
always_run : Bool = false
)
initialize(
name: name,
Expand Down Expand Up @@ -147,6 +147,7 @@ module Croupier

def stale?
# Tasks don't get stale twice
return true if @always_run
return false unless @stale

@stale = (
Expand Down Expand Up @@ -195,13 +196,11 @@ module Croupier

# Merge two tasks.
#
# inputs are joined
# inputs and outputs are joined
# procs of the second task are added to the 1st
def merge(other : Task)
raise "Cannot merge tasks with different no_save settings" \
unless no_save? == other.no_save?
raise "Cannot merge tasks with different always_run settings" \
unless always_run? == other.always_run?
raise "Cannot merge tasks with different no_save settings" unless no_save? == other.no_save?
raise "Cannot merge tasks with different always_run settings" unless always_run? == other.always_run?

# @outputs is NOT unique! We can save multiple times
@outputs += other.@outputs
Expand Down Expand Up @@ -397,10 +396,10 @@ module Croupier
# run_all will run all tasks, not just the ones that are stale
# dry_run will only log what would be done, but not actually do it
def self.run_tasks(
targets : Array(String),
run_all : Bool = false,
dry_run : Bool = false,
parallel : Bool = false,
targets : Array(String),
run_all : Bool = false,
dry_run : Bool = false,
parallel : Bool = false
)
mark_stale_inputs
tasks = dependencies(targets)
Expand All @@ -415,8 +414,8 @@ module Croupier
def self._run_tasks(outputs, run_all : Bool = false, dry_run : Bool = false)
outputs.each do |output|
if @@tasks.has_key?(output) && \
(run_all || @@tasks[output].stale? ||
@@tasks[output].@always_run)
(run_all || @@tasks[output].stale? ||
@@tasks[output].@always_run)
Log.debug { "Running task for #{output}" }
@@tasks[output].run unless dry_run
end
Expand All @@ -443,9 +442,11 @@ module Croupier
end

eligible_tasks = @@tasks.select { |k, _|
targets.includes? k
targets.includes? k
}

finished_tasks = Set(Task).new

errors = [] of String
loop do
stale_tasks = eligible_tasks.values.select { |t| t.stale? || t.always_run?}
Expand All @@ -460,7 +461,8 @@ module Croupier
rescue ex
errors << ex.message.to_s
ensure
t.not_ready
t.not_ready # FIXME shouldn't need this
finished_tasks << t
end
end
end
Expand Down

0 comments on commit 7b81dea

Please sign in to comment.