Skip to content

Commit

Permalink
Added dry_run flag
Browse files Browse the repository at this point in the history
  • Loading branch information
ralsina committed Jun 19, 2023
1 parent 1b067ae commit 5bcb2f4
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
4 changes: 3 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

## Version v0.1.8

* `always_run` for tasks that run even if their dependencies
* Added `always_run` flag for tasks that run even if their dependencies
are unchanged.
* Added `dry_run` flag for run_tasks, which will not actually run the
procs.

## Version v0.1.7

Expand Down
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Once it works fine with files, generalize to a k/v store using [kiwi](ihttps://github.com/crystal-community/kiwi)
* Make Task/TaskManager structs

* ~~Implement dry runs~~
* ~~Tasks that *always* run~~
* ~~Provide a way to ask to run tasks without outputs (needed for hacé)~~
* ~~Refactor the Task registry into its own class separate from Task itself~~
Expand Down
2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: croupier
version: 0.1.7
version: 0.1.8
description: A smart task definition and execution library
authors:
- Roberto Alsina <[email protected]>
Expand Down
11 changes: 11 additions & 0 deletions spec/croupier_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,17 @@ describe "Croupier::TaskManager" do
end
end

it "should run no tasks when dry_run is true" do
with_tasks do
Dir.cd "spec/files" do
Croupier::TaskManager.run_tasks(run_all: true, dry_run: true)
Croupier::TaskManager.tasks.keys.each do |k|
File.exists?(k).should be_false
end
end
end
end

it "should run all stale tasks when run_all is false" do
with_tasks do
Dir.cd "spec/files" do
Expand Down
15 changes: 8 additions & 7 deletions src/croupier.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require "log"
require "./topo_sort"

module Croupier
VERSION = "0.1.7"
VERSION = "0.1.8"

# A Task is an object that may generate output
#
Expand Down Expand Up @@ -369,10 +369,10 @@ module Croupier
end

# Run the tasks needed to create or update the requested targets
def self.run_tasks(targets : Array(String), run_all : Bool = false)
def self.run_tasks(targets : Array(String), run_all : Bool = false, dry_run : Bool = false)
mark_stale_inputs
tasks = dependencies(targets)
_run_tasks(tasks, run_all)
_run_tasks(tasks, run_all, dry_run)
end

# Check if all inputs are either task outputs or existing files
Expand All @@ -387,18 +387,19 @@ module Croupier
# Run all stale tasks in dependency order
#
# If `run_all` is true, run non-stale tasks too
def self.run_tasks(run_all : Bool = false)
def self.run_tasks(run_all : Bool = false, dry_run : Bool = false)
mark_stale_inputs
_, tasks = TaskManager.sorted_task_graph
check_dependencies
_run_tasks(tasks, run_all)
_run_tasks(tasks, run_all, dry_run)
end

# Helper to run tasks
def self._run_tasks(outputs, run_all : Bool = false)
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)
@@tasks[output].run
Log.info { "Running task for #{output}" }
@@tasks[output].run unless dry_run
end
end
save_run
Expand Down

0 comments on commit 5bcb2f4

Please sign in to comment.