rufio 0.50.0 → 0.60.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,118 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rufio
4
+ # ジョブ(タスク)の状態を管理するクラス
5
+ # status: :waiting, :running, :completed, :failed, :cancelled
6
+ class TaskStatus
7
+ attr_accessor :id, :name, :path, :status, :start_time, :end_time, :logs, :exit_code
8
+
9
+ # 初期化
10
+ # @param id [Integer] タスクID
11
+ # @param name [String] タスク名(スクリプト名)
12
+ # @param path [String] 実行ディレクトリ
13
+ def initialize(id:, name:, path:)
14
+ @id = id
15
+ @name = name
16
+ @path = path
17
+ @status = :waiting
18
+ @start_time = nil
19
+ @end_time = nil
20
+ @logs = []
21
+ @exit_code = nil
22
+ end
23
+
24
+ # タスクを開始する
25
+ def start
26
+ @status = :running
27
+ @start_time = Time.now
28
+ end
29
+
30
+ # タスクを完了する
31
+ # @param exit_code [Integer] 終了コード
32
+ def complete(exit_code:)
33
+ @status = :completed
34
+ @end_time = Time.now
35
+ @exit_code = exit_code
36
+ end
37
+
38
+ # タスクを失敗させる
39
+ # @param exit_code [Integer] 終了コード
40
+ def fail(exit_code:)
41
+ @status = :failed
42
+ @end_time = Time.now
43
+ @exit_code = exit_code
44
+ end
45
+
46
+ # タスクをキャンセルする
47
+ def cancel
48
+ @status = :cancelled
49
+ @end_time = Time.now
50
+ end
51
+
52
+ # 実行時間を取得
53
+ # @return [Float, nil] 秒単位の実行時間(未開始の場合はnil)
54
+ def duration
55
+ return nil unless @start_time
56
+
57
+ (@end_time || Time.now) - @start_time
58
+ end
59
+
60
+ # ログを追加
61
+ # @param line [String] ログ行
62
+ def append_log(line)
63
+ @logs << line
64
+ end
65
+
66
+ # 実行中かどうか
67
+ # @return [Boolean]
68
+ def running?
69
+ @status == :running
70
+ end
71
+
72
+ # 完了したかどうか
73
+ # @return [Boolean]
74
+ def completed?
75
+ @status == :completed
76
+ end
77
+
78
+ # 失敗したかどうか
79
+ # @return [Boolean]
80
+ def failed?
81
+ @status == :failed
82
+ end
83
+
84
+ # キャンセルされたかどうか
85
+ # @return [Boolean]
86
+ def cancelled?
87
+ @status == :cancelled
88
+ end
89
+
90
+ # ステータスアイコンを取得
91
+ # @return [String] ステータスアイコン
92
+ def status_icon
93
+ case @status
94
+ when :waiting
95
+ '⏸'
96
+ when :running
97
+ '⚙'
98
+ when :completed
99
+ '✓'
100
+ when :failed
101
+ '✗'
102
+ when :cancelled
103
+ '⏹'
104
+ else
105
+ '?'
106
+ end
107
+ end
108
+
109
+ # フォーマット済みの実行時間を取得
110
+ # @return [String] "12.4s" 形式の文字列(未開始の場合は空文字列)
111
+ def formatted_duration
112
+ d = duration
113
+ return '' unless d
114
+
115
+ format('%.1fs', d)
116
+ end
117
+ end
118
+ end