Class: UniPod::Server::PackageBuilderQueue::BuildTask
- Inherits:
-
Object
- Object
- UniPod::Server::PackageBuilderQueue::BuildTask
- Defined in:
- lib/unipod/server/package_builder_queue.rb
Overview
表示要构建的包任务
Instance Attribute Summary collapse
-
#callbacks ⇒ Object
readonly
Returns the value of attribute callbacks.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#git_branch ⇒ Object
readonly
Returns the value of attribute git_branch.
-
#git_tag ⇒ Object
readonly
Returns the value of attribute git_tag.
-
#git_url ⇒ Object
readonly
Returns the value of attribute git_url.
-
#package_name ⇒ Object
readonly
Returns the value of attribute package_name.
-
#priority ⇒ Object
readonly
Returns the value of attribute priority.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
-
#add_callback(&block) ⇒ Object
添加任务完成后的回调函数.
-
#execute_callbacks(success, tarball_path = nil) ⇒ Object
执行所有回调.
-
#initialize(package_name, version, git_url, git_tag = nil, git_branch = nil, priority = 0) ⇒ BuildTask
constructor
A new instance of BuildTask.
-
#key ⇒ Object
生成任务的唯一键.
-
#to_s ⇒ Object
打印任务信息.
-
#wait_time ⇒ Object
任务已等待时间(秒).
Constructor Details
#initialize(package_name, version, git_url, git_tag = nil, git_branch = nil, priority = 0) ⇒ BuildTask
Returns a new instance of BuildTask.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/unipod/server/package_builder_queue.rb', line 16 def initialize(package_name, version, git_url, git_tag = nil, git_branch = nil, priority = 0) @package_name = package_name @version = version @git_url = git_url @git_tag = git_tag || "v#{version}" @git_branch = git_branch || 'main' @priority = priority # 优先级:0=普通,1=高优先级(当前请求的包) @created_at = Time.now @callbacks = [] end |
Instance Attribute Details
#callbacks ⇒ Object (readonly)
Returns the value of attribute callbacks.
14 15 16 |
# File 'lib/unipod/server/package_builder_queue.rb', line 14 def callbacks @callbacks end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
14 15 16 |
# File 'lib/unipod/server/package_builder_queue.rb', line 14 def created_at @created_at end |
#git_branch ⇒ Object (readonly)
Returns the value of attribute git_branch.
14 15 16 |
# File 'lib/unipod/server/package_builder_queue.rb', line 14 def git_branch @git_branch end |
#git_tag ⇒ Object (readonly)
Returns the value of attribute git_tag.
14 15 16 |
# File 'lib/unipod/server/package_builder_queue.rb', line 14 def git_tag @git_tag end |
#git_url ⇒ Object (readonly)
Returns the value of attribute git_url.
14 15 16 |
# File 'lib/unipod/server/package_builder_queue.rb', line 14 def git_url @git_url end |
#package_name ⇒ Object (readonly)
Returns the value of attribute package_name.
14 15 16 |
# File 'lib/unipod/server/package_builder_queue.rb', line 14 def package_name @package_name end |
#priority ⇒ Object (readonly)
Returns the value of attribute priority.
14 15 16 |
# File 'lib/unipod/server/package_builder_queue.rb', line 14 def priority @priority end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
14 15 16 |
# File 'lib/unipod/server/package_builder_queue.rb', line 14 def version @version end |
Instance Method Details
#add_callback(&block) ⇒ Object
添加任务完成后的回调函数
28 29 30 |
# File 'lib/unipod/server/package_builder_queue.rb', line 28 def add_callback(&block) @callbacks << block if block_given? end |
#execute_callbacks(success, tarball_path = nil) ⇒ Object
执行所有回调
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/unipod/server/package_builder_queue.rb', line 33 def execute_callbacks(success, tarball_path = nil) @callbacks.each do |callback| begin callback.call(success, tarball_path) rescue => e # 忽略回调中的错误,避免影响队列处理 UI.error "执行包构建回调时出错: #{e.}" if verbose? end end end |
#key ⇒ Object
生成任务的唯一键
45 46 47 |
# File 'lib/unipod/server/package_builder_queue.rb', line 45 def key "#{@package_name}-#{@version}" end |
#to_s ⇒ Object
打印任务信息
55 56 57 |
# File 'lib/unipod/server/package_builder_queue.rb', line 55 def to_s "BuildTask[#{@package_name}@#{@version}, git:#{@git_url}, tag:#{@git_tag}, priority:#{@priority}]" end |
#wait_time ⇒ Object
任务已等待时间(秒)
50 51 52 |
# File 'lib/unipod/server/package_builder_queue.rb', line 50 def wait_time Time.now - @created_at end |