Class: Rufio::TaskStatus
- Inherits:
-
Object
- Object
- Rufio::TaskStatus
- Defined in:
- lib/rufio/task_status.rb
Overview
ジョブ(タスク)の状態を管理するクラスstatus: :waiting, :running, :completed, :failed, :cancelled
Instance Attribute Summary collapse
-
#end_time ⇒ Object
Returns the value of attribute end_time.
-
#exit_code ⇒ Object
Returns the value of attribute exit_code.
-
#id ⇒ Object
Returns the value of attribute id.
-
#logs ⇒ Object
Returns the value of attribute logs.
-
#name ⇒ Object
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
-
#start_time ⇒ Object
Returns the value of attribute start_time.
-
#status ⇒ Object
Returns the value of attribute status.
Instance Method Summary collapse
-
#append_log(line) ⇒ Object
ログを追加.
-
#cancel ⇒ Object
タスクをキャンセルする.
-
#cancelled? ⇒ Boolean
キャンセルされたかどうか.
-
#complete(exit_code:) ⇒ Object
タスクを完了する.
-
#completed? ⇒ Boolean
完了したかどうか.
-
#duration ⇒ Float?
実行時間を取得.
-
#fail(exit_code:) ⇒ Object
タスクを失敗させる.
-
#failed? ⇒ Boolean
失敗したかどうか.
-
#formatted_duration ⇒ String
フォーマット済みの実行時間を取得.
-
#initialize(id:, name:, path:) ⇒ TaskStatus
constructor
初期化.
-
#running? ⇒ Boolean
実行中かどうか.
-
#start ⇒ Object
タスクを開始する.
-
#status_icon ⇒ String
ステータスアイコンを取得.
Constructor Details
#initialize(id:, name:, path:) ⇒ TaskStatus
初期化
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rufio/task_status.rb', line 13 def initialize(id:, name:, path:) @id = id @name = name @path = path @status = :waiting @start_time = nil @end_time = nil @logs = [] @exit_code = nil end |
Instance Attribute Details
#end_time ⇒ Object
Returns the value of attribute end_time.
7 8 9 |
# File 'lib/rufio/task_status.rb', line 7 def end_time @end_time end |
#exit_code ⇒ Object
Returns the value of attribute exit_code.
7 8 9 |
# File 'lib/rufio/task_status.rb', line 7 def exit_code @exit_code end |
#id ⇒ Object
Returns the value of attribute id.
7 8 9 |
# File 'lib/rufio/task_status.rb', line 7 def id @id end |
#logs ⇒ Object
Returns the value of attribute logs.
7 8 9 |
# File 'lib/rufio/task_status.rb', line 7 def logs @logs end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/rufio/task_status.rb', line 7 def name @name end |
#path ⇒ Object
Returns the value of attribute path.
7 8 9 |
# File 'lib/rufio/task_status.rb', line 7 def path @path end |
#start_time ⇒ Object
Returns the value of attribute start_time.
7 8 9 |
# File 'lib/rufio/task_status.rb', line 7 def start_time @start_time end |
#status ⇒ Object
Returns the value of attribute status.
7 8 9 |
# File 'lib/rufio/task_status.rb', line 7 def status @status end |
Instance Method Details
#append_log(line) ⇒ Object
ログを追加
62 63 64 |
# File 'lib/rufio/task_status.rb', line 62 def append_log(line) @logs << line end |
#cancel ⇒ Object
タスクをキャンセルする
47 48 49 50 |
# File 'lib/rufio/task_status.rb', line 47 def cancel @status = :cancelled @end_time = Time.now end |
#cancelled? ⇒ Boolean
キャンセルされたかどうか
86 87 88 |
# File 'lib/rufio/task_status.rb', line 86 def cancelled? @status == :cancelled end |
#complete(exit_code:) ⇒ Object
タスクを完了する
32 33 34 35 36 |
# File 'lib/rufio/task_status.rb', line 32 def complete(exit_code:) @status = :completed @end_time = Time.now @exit_code = exit_code end |
#completed? ⇒ Boolean
完了したかどうか
74 75 76 |
# File 'lib/rufio/task_status.rb', line 74 def completed? @status == :completed end |
#duration ⇒ Float?
実行時間を取得
54 55 56 57 58 |
# File 'lib/rufio/task_status.rb', line 54 def duration return nil unless @start_time (@end_time || Time.now) - @start_time end |
#fail(exit_code:) ⇒ Object
タスクを失敗させる
40 41 42 43 44 |
# File 'lib/rufio/task_status.rb', line 40 def fail(exit_code:) @status = :failed @end_time = Time.now @exit_code = exit_code end |
#failed? ⇒ Boolean
失敗したかどうか
80 81 82 |
# File 'lib/rufio/task_status.rb', line 80 def failed? @status == :failed end |
#formatted_duration ⇒ String
フォーマット済みの実行時間を取得
111 112 113 114 115 116 |
# File 'lib/rufio/task_status.rb', line 111 def formatted_duration d = duration return '' unless d format('%.1fs', d) end |
#running? ⇒ Boolean
実行中かどうか
68 69 70 |
# File 'lib/rufio/task_status.rb', line 68 def running? @status == :running end |
#start ⇒ Object
タスクを開始する
25 26 27 28 |
# File 'lib/rufio/task_status.rb', line 25 def start @status = :running @start_time = Time.now end |
#status_icon ⇒ String
ステータスアイコンを取得
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/rufio/task_status.rb', line 92 def status_icon case @status when :waiting '⏸' when :running '⚙' when :completed '✓' when :failed '✗' when :cancelled '⏹' else '?' end end |