Class: JiraImportState

Inherits:
ApplicationRecord show all
Includes:
AfterCommitQueue, ImportState::SidekiqJobTracker, UsageStatistics
Defined in:
app/models/jira_import_state.rb

Constant Summary collapse

ERROR_MESSAGE_SIZE =

1000 characters limit

1000
STATUSES =
{ initial: 0, scheduled: 1, started: 2, failed: 3, finished: 4 }.freeze

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from ResetOnUnionError

ResetOnUnionError::MAX_RESET_PERIOD

Instance Method Summary collapse

Methods included from AfterCommitQueue

#run_after_commit, #run_after_commit_or_now

Methods inherited from ApplicationRecord

cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order

Methods included from SensitiveSerializableHash

#serializable_hash

Instance Method Details

#in_progress?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'app/models/jira_import_state.rb', line 89

def in_progress?
  scheduled? || started?
end

#mark_as_failed(error_message) ⇒ Object



113
114
115
116
117
118
119
# File 'app/models/jira_import_state.rb', line 113

def mark_as_failed(error_message)
  sanitized_message = Gitlab::UrlSanitizer.sanitize(error_message)

  do_fail(error_message: error_message)
rescue ActiveRecord::ActiveRecordError => e
  Gitlab::AppLogger.error("Error setting import status to failed: #{e.message}. Original error: #{sanitized_message}")
end

#non_initial?Boolean

Returns:

  • (Boolean)


93
94
95
# File 'app/models/jira_import_state.rb', line 93

def non_initial?
  !initial?
end

#store_issue_countsObject



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'app/models/jira_import_state.rb', line 97

def store_issue_counts
  import_label_id = Gitlab::JiraImport.get_import_label_id(project.id)

  failed_to_import_count = Gitlab::JiraImport.issue_failures(project.id)
  successfully_imported_count = project.issues.with_label_ids(import_label_id).count
  total_issue_count = successfully_imported_count + failed_to_import_count

  update(
    {
      failed_to_import_count: failed_to_import_count,
      imported_issues_count: successfully_imported_count,
      total_issue_count: total_issue_count
    }
  )
end