lib/makit/command_runner.rb in makit-0.0.27 vs lib/makit/command_runner.rb in makit-0.0.28

- old
+ new

@@ -9,17 +9,18 @@ module Makit # This class provide methods running commands. # class CommandRunner attr_accessor :show_output_on_success, :log_to_artifacts, :commands - attr_accessor :debug + attr_accessor :debug, :default_modified def initialize @show_output_on_success = false @log_to_artifacts = false @commands = [] @debug = false + @default_modified = Makit::Git::get_file_infos.first.mtime # Makit::GIT_FILE_INFOS.first.mtime end def get_cache_filename(command) int_hash = Digest::SHA256.hexdigest("#{command.name}.#{command.arguments.join(" ")}") hash_string = "#{int_hash}" @@ -28,16 +29,25 @@ # create the directory if it does not already exist FileUtils.mkdir_p(File.dirname(cache_filename)) cache_filename end + def cache_run(command_request) + cache_run(command_request, @default_modified) + end + # if there is a matching cached command result, that then the specified timestamp, # then return the cached result # otherwise run the command and save the result to a cache file # then return the result def cache_run(command_request, timestamp) raise "Invalid command_request" unless command_request.is_a? Makit::V1::CommandRequest cache_filename = get_cache_filename(command_request) + + # Check if timestamp is a valid Time object + unless timestamp.is_a?(Time) + raise ArgumentError, "timestamp must be a Time object, got #{timestamp.class}" + end if debug puts " timestamp: #{Makit::Humanize.get_humanized_timestamp(timestamp)}" puts " command.name: #{command_request.name}" puts " command.arguments: #{command_request.arguments.join(" ")}"