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. 自动模式:只传入 project_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, #data_dependencies, #dependencies, #error, #finished_at, #id, #max_retry_count, #metadata, #name, #priority, #result, #retry_count, #retry_delay, #retry_mode, #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, #reset_for_retry, #retryable?, #running?, #should_retry?, task_type

Constructor Details

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

初始化 Media 上传任务

Parameters:

  • file_paths (Array<String>)

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

  • 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 描述(可选)

  • :workflow_id (Integer)

    工作流ID(可选,用于筛选 commit_log)

  • :project_name (String)

    项目名称(可选)

  • :project_path (String)

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



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

def initialize(file_paths, options = {})
  @file_paths = file_paths || []                  # 要上传的文件路径列表
  @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 描述
  @workflow_id = options[:workflow_id]            # 工作流ID
  @project_path = options[:project_path]          # 项目路径

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

  name = "上传 Media 附件"

  super(name, options)
end

Instance Attribute Details

#file_pathsObject (readonly)

Returns the value of attribute file_paths.



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

def file_paths
  @file_paths
end

#git_commit_descObject (readonly)

Returns the value of attribute git_commit_desc.



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

def git_commit_desc
  @git_commit_desc
end

#git_commit_idObject (readonly)

Returns the value of attribute git_commit_id.



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

def git_commit_id
  @git_commit_id
end

#git_commit_timeObject (readonly)

Returns the value of attribute git_commit_time.



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

def git_commit_time
  @git_commit_time
end

#project_pathObject (readonly)

Returns the value of attribute project_path.



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

def project_path
  @project_path
end

#workflow_idObject (readonly)

Returns the value of attribute workflow_id.



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

def workflow_id
  @workflow_id
end

Class Method Details

.default_retry_countObject



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

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

.default_retry_delayObject



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

def self.default_retry_delay
  5  # 延迟 5 秒
end

.default_retry_modeObject

Media 上传任务重试配置



61
62
63
# File 'lib/pindo/module/task/model/jps/jps_upload_media_task.rb', line 61

def self.default_retry_mode
  RetryMode::DELAYED
end

.task_keyObject

任务键



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

def self.task_key
  :jps_upload_media
end

Instance Method Details

#validateObject



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

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

  true
end