Class: Pindo::TaskSystem::UploadTask

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

Overview

上传任务上传构建产物到测试平台(JPS)

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, #started_at, #status, #type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PindoTask

#before_retry, #cancel, #cancelled?, #check_cancelled!, #do_task, #execution_time, #finished?, #on, #reset_for_retry, #retryable?, #running?, #should_retry?

Constructor Details

#initialize(file_type, upload_path, upload_file, options = {}) ⇒ UploadTask

初始化上传任务

Parameters:

  • file_type (String)

    文件类型:‘ipa’ | ‘apk’ | ‘html’ | ‘app’

  • upload_path (String)

    搜索文件的路径

  • upload_file (String)

    要上传的文件(nil 表示自动查找)

  • options (Hash) (defaults to: {})

    选项

Options Hash (options):

  • :app_info_obj (Hash)

    JPS 应用信息对象(可选,如为 nil 则延迟获取)

  • :workflow_info (Hash)

    工作流信息(可选,如为 nil 则延迟获取)

  • :project_name (String)

    项目名称(可选)



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/pindo/module/task/model/upload_task.rb', line 37

def initialize(file_type, upload_path, upload_file, options = {})
  @file_type = file_type        # 'ipa' | 'apk' | 'html' | 'app'
  @upload_path = upload_path    # 搜索文件的路径
  @upload_file = upload_file    # 要上传的文件(nil 表示自动查找)

  # 可选参数(如果为 nil,在 do_work 中延迟获取)
  @app_info_obj = options[:app_info_obj]
  @workflow_info = options[:workflow_info]
  @project_name = options[:project_name]

  # 设置上传任务的优先级为 LOW,确保在构建任务之后执行
  options[:priority] ||= TaskPriority::LOW

  name = case file_type
         when 'ipa'
           "上传 IPA"
         when 'apk'
           "上传 APK"
         when 'html'
           "上传 WebGL"
         when 'app'
           "上传 macOS App"
         else
           "上传 #{file_type.upcase}"
         end

  super(name, options)
end

Instance Attribute Details

#file_typeObject (readonly)

Returns the value of attribute file_type.



10
11
12
# File 'lib/pindo/module/task/model/upload_task.rb', line 10

def file_type
  @file_type
end

#upload_fileObject (readonly)

Returns the value of attribute upload_file.



10
11
12
# File 'lib/pindo/module/task/model/upload_task.rb', line 10

def upload_file
  @upload_file
end

#upload_pathObject (readonly)

Returns the value of attribute upload_path.



10
11
12
# File 'lib/pindo/module/task/model/upload_task.rb', line 10

def upload_path
  @upload_path
end

Class Method Details

.default_retry_countObject



21
22
23
# File 'lib/pindo/module/task/model/upload_task.rb', line 21

def self.default_retry_count
  3  # 默认可以重试 3 次
end

.default_retry_delayObject



25
26
27
# File 'lib/pindo/module/task/model/upload_task.rb', line 25

def self.default_retry_delay
  10  # 默认延迟 10 秒
end

.default_retry_modeObject

重试配置



17
18
19
# File 'lib/pindo/module/task/model/upload_task.rb', line 17

def self.default_retry_mode
  RetryMode::DELAYED  # 延迟重试
end

.task_typeObject



12
13
14
# File 'lib/pindo/module/task/model/upload_task.rb', line 12

def self.task_type
  :upload
end

Instance Method Details

#validateObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/pindo/module/task/model/upload_task.rb', line 66

def validate
  # 验证基本参数
  unless @file_type && !@file_type.empty?
    @error = "缺少必需参数: file_type"
    return false
  end

  unless @upload_path && !@upload_path.empty?
    @error = "缺少必需参数: upload_path"
    return false
  end

  # upload_path 可能在构建任务执行后才创建,这里不验证是否存在
  # 实际文件查找会在 do_work 中进行

  # app_info_obj 和 workflow_info 可以延迟获取,不在这里验证

  true
end