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
19
# 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
  @auto_kill = options[:auto_kill] || false

  super(name, options)
end

Instance Attribute Details

#auto_killObject (readonly)

Returns the value of attribute auto_kill.



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

def auto_kill
  @auto_kill
end

#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



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

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

.default_retry_delayObject



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

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

.default_retry_modeObject

Unity 任务默认重试配置



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

def self.default_retry_mode
  RetryMode::DELAYED
end

.task_typeObject

Unity 任务类型



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

def self.task_type
  :unity
end

.task_type_nameObject

Unity 任务类型显示名称



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

def self.task_type_name
  "Unity操作"
end

Instance Method Details

#before_retryObject

重试前清理 Unity 进程



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

def before_retry
  super
  cleanup_unity_processes
end

#normalize_path(path) ⇒ Object

规范化路径辅助方法



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

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

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



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

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



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

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

#validateObject

验证 Unity 项目路径



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

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