Class: Pindo::TaskSystem::JPSUploadMediaTask

Inherits:
JPSTask show all
Defined in:
lib/pindo/module/task/model/jps/jps_upload_media_task.rb

Overview

JPS Media 上传任务上传图片、视频等 media 文件到 JPS 并关联到提交记录

支持两种模式:

  1. 指定模式:传入 file_paths 和 git_commit_id

  2. 自动模式:只传入 upload_path,自动查找 JPSMedia/ 目录和 git HEAD 信息

Constant Summary collapse

MEDIA_EXTENSIONS =

支持的媒体文件扩展名

%w[png jpg jpeg gif bmp webp mp4 mov avi mkv webm].freeze

Instance Attribute Summary collapse

Attributes inherited from JPSTask

#app_info_obj, #project_name, #workflow_info

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 JPSTask

task_type, task_type_name

Methods inherited from PindoTask

#before_retry, #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, #required_resources, #reset_for_retry, #retryable?, #running?, #should_retry?, task_type, #with_resource, #with_resources

Constructor Details

#initialize(file_paths, upload_path, options = {}) ⇒ JPSUploadMediaTask

初始化 Media 上传任务

Parameters:

  • file_paths (Array<String>)

    要上传的文件路径列表(可选,为空时自动查找)

  • upload_path (String)

    项目路径(必需,用于查找 git 仓库和 JPSMedia 目录)

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

    选项

Options Hash (options):

  • :git_commit_id (String)

    Git commit SHA(可选,为空时自动获取 HEAD)

  • :git_commit_time (String)

    Git commit 时间(可选)

  • :git_commit_desc (String)

    Git commit 描述(可选)

  • :app_info_obj (Hash)

    JPS 应用信息对象(可选,继承自基类)

  • :workflow_info (Hash)

    工作流信息(可选,继承自基类)

  • :project_name (String)

    项目名称(可选,继承自基类)



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/pindo/module/task/model/jps/jps_upload_media_task.rb', line 36

def initialize(file_paths, upload_path, options = {})
  @file_paths = file_paths || []                  # 要上传的文件路径列表
  @upload_path = upload_path                      # 项目路径
  @git_commit_id = options[:git_commit_id]        # Git commit SHA
  @git_commit_time = options[:git_commit_time]    # Git commit 时间
  @git_commit_desc = options[:git_commit_desc]    # Git commit 描述

  # 设置任务优先级为 LOW,确保在其他任务之后执行
  options[:priority] ||= TaskPriority::LOW

  name = "上传 Media 附件"

  super(name, options)
end

Instance Attribute Details

#file_pathsObject (readonly)

Returns the value of attribute file_paths.



15
16
17
# File 'lib/pindo/module/task/model/jps/jps_upload_media_task.rb', line 15

def file_paths
  @file_paths
end

#git_commit_descObject (readonly)

Returns the value of attribute git_commit_desc.



15
16
17
# File 'lib/pindo/module/task/model/jps/jps_upload_media_task.rb', line 15

def git_commit_desc
  @git_commit_desc
end

#git_commit_idObject (readonly)

Returns the value of attribute git_commit_id.



15
16
17
# File 'lib/pindo/module/task/model/jps/jps_upload_media_task.rb', line 15

def git_commit_id
  @git_commit_id
end

#git_commit_timeObject (readonly)

Returns the value of attribute git_commit_time.



15
16
17
# File 'lib/pindo/module/task/model/jps/jps_upload_media_task.rb', line 15

def git_commit_time
  @git_commit_time
end

#upload_pathObject (readonly)

Returns the value of attribute upload_path.



16
17
18
# File 'lib/pindo/module/task/model/jps/jps_upload_media_task.rb', line 16

def upload_path
  @upload_path
end

Class Method Details

.default_retry_countObject



68
69
70
# File 'lib/pindo/module/task/model/jps/jps_upload_media_task.rb', line 68

def self.default_retry_count
  2  # Media 上传重试次数较少
end

.default_retry_delayObject



72
73
74
# File 'lib/pindo/module/task/model/jps/jps_upload_media_task.rb', line 72

def self.default_retry_delay
  5  # 延迟 5 秒
end

.default_retry_modeObject

Media 上传任务重试配置



64
65
66
# File 'lib/pindo/module/task/model/jps/jps_upload_media_task.rb', line 64

def self.default_retry_mode
  RetryMode::DELAYED
end

.task_keyObject

任务键



22
23
24
# File 'lib/pindo/module/task/model/jps/jps_upload_media_task.rb', line 22

def self.task_key
  :jps_upload_media
end

Instance Method Details

#validateObject



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/pindo/module/task/model/jps/jps_upload_media_task.rb', line 51

def validate
  # 验证 upload_path(必需参数)
  unless @upload_path && !@upload_path.empty? && Dir.exist?(@upload_path)
    @error = "缺少必需参数: upload_path(项目路径)或路径不存在"
    return false
  end

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

  true
end