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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AfterCommitQueue

#run_after_commit, #run_after_commit_or_now

Methods inherited from ApplicationRecord

at_most, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, underscore, without_order

Class Method Details

.finished_imports_countObject


113
114
115
# File 'app/models/jira_import_state.rb', line 113

def self.finished_imports_count
  finished.sum(:imported_issues_count)
end

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


117
118
119
120
121
122
123
# File 'app/models/jira_import_state.rb', line 117

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