Class: Pindo::TaskSystem::UnityTask

Inherits:
PindoTask
  • Object
show all
Defined in:
lib/pindo/module/task/model/unity_task.rb

Overview

Unity 任务基类所有 Unity 相关任务的父类,提供通用的 Unity 操作和配置

Instance Attribute Summary collapse

Attributes inherited from PindoTask

#callbacks_setup, #context, #created_at, #dependencies, #error, #finished_at, #id, #max_retry_count, #metadata, #name, #priority, #result, #retry_count, #retry_delay, #retry_mode, #skip_count, #started_at, #status, #task_key, #task_manager, #type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PindoTask

#cancel, #cancelled?, #check_cancelled!, #data_param, #do_task, #execution_time, #finished?, #get_all_data_params, #get_all_data_params_by_key, #get_all_dependencies_results, #get_data_param, #get_data_param_by_key, #get_dependency_result, #get_dependency_task, #on, #primary_data_param, #release_resource, #release_resources, #reset_for_retry, #retryable?, #running?, #should_retry?, task_key, #with_resource, #with_resources

Constructor Details

#initialize(name, options = {}) ⇒ UnityTask

Returns a new instance of UnityTask.



13
14
15
16
17
18
# File 'lib/pindo/module/task/model/unity_task.rb', line 13

def initialize(name, options = {})
  @project_path = options[:project_path] ? normalize_path(options[:project_path]) : nil
  @unity_root_path = options[:unity_root_path] ? normalize_path(options[:unity_root_path]) : @project_path

  super(name, options)
end

Instance Attribute Details

#project_pathObject (readonly)

Returns the value of attribute project_path.



11
12
13
# File 'lib/pindo/module/task/model/unity_task.rb', line 11

def project_path
  @project_path
end

#unity_root_pathObject (readonly)

Returns the value of attribute unity_root_path.



11
12
13
# File 'lib/pindo/module/task/model/unity_task.rb', line 11

def unity_root_path
  @unity_root_path
end

Class Method Details

.default_retry_countObject



45
46
47
# File 'lib/pindo/module/task/model/unity_task.rb', line 45

def self.default_retry_count
  2  # Unity 任务默认重试 2 次
end

.default_retry_delayObject



49
50
51
# File 'lib/pindo/module/task/model/unity_task.rb', line 49

def self.default_retry_delay
  15  # Unity 任务默认延迟 15 秒重试
end

.default_retry_modeObject

Unity 任务默认重试配置



41
42
43
# File 'lib/pindo/module/task/model/unity_task.rb', line 41

def self.default_retry_mode
  RetryMode::DELAYED
end

.task_typeObject

Unity 任务类型



31
32
33
# File 'lib/pindo/module/task/model/unity_task.rb', line 31

def self.task_type
  :unity
end

.task_type_nameObject

Unity 任务类型显示名称



36
37
38
# File 'lib/pindo/module/task/model/unity_task.rb', line 36

def self.task_type_name
  "Unity操作"
end

Instance Method Details

#before_retryObject

重试前清理 Unity 进程



85
86
87
88
# File 'lib/pindo/module/task/model/unity_task.rb', line 85

def before_retry
  super
  cleanup_unity_processes
end

#normalize_path(path) ⇒ Object

规范化路径辅助方法



21
22
23
24
25
26
27
28
# File 'lib/pindo/module/task/model/unity_task.rb', line 21

def normalize_path(path)
  return nil if path.nil?
  begin
    File.realpath(File.expand_path(path))
  rescue
    File.expand_path(path)
  end
end

#required_resourcesObject

声明所需资源(锁住项目目录,防止并发执行)



74
75
76
77
78
79
80
81
82
# File 'lib/pindo/module/task/model/unity_task.rb', line 74

def required_resources
  # 1. Unity 资源:锁定 Unity 项目目录
  # 2. Build 资源:锁定构建目录(git 仓库或项目目录)
  build_lock_dir = get_build_lock_directory
  (super || []) + [
    { type: :unity, directory: @unity_root_path },
    { type: :build, directory: build_lock_dir }
  ]
end

#unity_helperObject

获取 Unity Helper



69
70
71
# File 'lib/pindo/module/task/model/unity_task.rb', line 69

def unity_helper
  @unity_helper ||= Pindo::Unity::UnityHelper.share_instance
end

#validateObject

验证 Unity 项目路径



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/pindo/module/task/model/unity_task.rb', line 54

def validate
  super

  unless File.directory?(@project_path)
    raise Informative, "Unity 项目路径不存在: #{@project_path}"
  end

  unless File.directory?(@unity_root_path)
    raise Informative, "Unity 根目录不存在: #{@unity_root_path}"
  end

  true
end