Class: RecordLoader::TaskLoader

Inherits:
ApplicationRecordLoader show all
Defined in:
lib/record_loader/task_loader.rb

Overview

Creates the specified Task if they are not present

Instance Method Summary collapse

Methods inherited from ApplicationRecordLoader

#wip_list

Instance Method Details

#create_or_update!(name, options) ⇒ Task?

Creates a Task with the given name and options. This method first retrieves the associated Workflow by its name. If the Workflow it logs a warning and returns nil in development, staging, or cucumber environments. In all other environments, it raises an ActiveRecord::RecordNotFound exception. If the Workflow is found, it assigns its ID to the pipeline_workflow_id attribute and creates or updates the Task.

development, staging, or cucumber.

Parameters:

  • name (String)

    The name of the Task.

  • options (Hash)

    The options for creating or updating the Task.

Returns:

  • (Task, nil)

    The created Task, or nil if the Workflow is not found in specific environments.

Raises:



25
26
27
28
29
30
31
32
# File 'lib/record_loader/task_loader.rb', line 25

def create_or_update!(name, options)
  workflow_name = options.delete('workflow')
  workflow = find_workflow!(workflow_name, name)
  return unless workflow

  options[:pipeline_workflow_id] = workflow.id
  Task.create_with(options).find_or_create_by!(name: name, pipeline_workflow_id: workflow.id)
end