Class: Rufio::ScriptRunner
- Inherits:
-
Object
- Object
- Rufio::ScriptRunner
- Defined in:
- lib/rufio/script_runner.rb
Overview
スクリプトパスからスクリプトを検索・実行するクラスジョブマネージャーと連携してバックグラウンド実行を管理
Constant Summary collapse
- SUPPORTED_EXTENSIONS =
サポートするスクリプト拡張子
%w[.sh .rb .py .pl .js .ts .ps1].freeze
Instance Method Summary collapse
-
#available_scripts ⇒ Array<Hash>
利用可能なスクリプト一覧を取得.
-
#clear_cache ⇒ Object
キャッシュをクリア.
-
#complete(prefix) ⇒ Array<String>
スクリプト名の補完候補を取得.
-
#find_script(name) ⇒ Hash?
スクリプト名で検索.
-
#initialize(script_paths:, job_manager: nil, command_logger: nil) ⇒ ScriptRunner
constructor
A new instance of ScriptRunner.
-
#run(name, working_dir:, args: nil, selected_file: nil, selected_dir: nil) ⇒ TaskStatus?
スクリプトをジョブとして実行.
Constructor Details
#initialize(script_paths:, job_manager: nil, command_logger: nil) ⇒ ScriptRunner
Returns a new instance of ScriptRunner.
15 16 17 18 19 20 |
# File 'lib/rufio/script_runner.rb', line 15 def initialize(script_paths:, job_manager: nil, command_logger: nil) @script_paths = script_paths.map { |p| File.(p) } @job_manager = job_manager @command_logger = command_logger @scripts_cache = nil end |
Instance Method Details
#available_scripts ⇒ Array<Hash>
利用可能なスクリプト一覧を取得
24 25 26 |
# File 'lib/rufio/script_runner.rb', line 24 def available_scripts @scripts_cache ||= scan_scripts end |
#clear_cache ⇒ Object
キャッシュをクリア
72 73 74 |
# File 'lib/rufio/script_runner.rb', line 72 def clear_cache @scripts_cache = nil end |
#complete(prefix) ⇒ Array<String>
スクリプト名の補完候補を取得
48 49 50 51 52 53 54 |
# File 'lib/rufio/script_runner.rb', line 48 def complete(prefix) available_scripts .map { |s| s[:name] } .select { |name| name.start_with?(prefix) } .uniq .sort end |
#find_script(name) ⇒ Hash?
スクリプト名で検索
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rufio/script_runner.rb', line 31 def find_script(name) # 完全一致を優先 script = available_scripts.find { |s| s[:name] == name } return script if script # 拡張子なしで検索 SUPPORTED_EXTENSIONS.each do |ext| script = available_scripts.find { |s| s[:name] == "#{name}#{ext}" } return script if script end nil end |
#run(name, working_dir:, args: nil, selected_file: nil, selected_dir: nil) ⇒ TaskStatus?
スクリプトをジョブとして実行
63 64 65 66 67 68 69 |
# File 'lib/rufio/script_runner.rb', line 63 def run(name, working_dir:, args: nil, selected_file: nil, selected_dir: nil) script = find_script(name) return nil unless script env = build_environment(working_dir, selected_file, selected_dir) execute_script(script, working_dir, env, args) end |