forked from gitlabhq/gitlabhq
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add latest changes from gitlab-org/gitlab@master
- Loading branch information
GitLab Bot
committed
Apr 6, 2020
1 parent
f098e6d
commit cce8cf0
Showing
21 changed files
with
567 additions
and
236 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# frozen_string_literal: true | ||
|
||
class JiraImportState < ApplicationRecord | ||
include AfterCommitQueue | ||
|
||
self.table_name = 'jira_imports' | ||
|
||
STATUSES = { initial: 0, scheduled: 1, started: 2, failed: 3, finished: 4 }.freeze | ||
|
||
belongs_to :project | ||
belongs_to :user | ||
belongs_to :label | ||
|
||
validates :project, presence: true | ||
validates :jira_project_key, presence: true | ||
validates :jira_project_name, presence: true | ||
validates :jira_project_xid, presence: true | ||
|
||
validates :project, uniqueness: { | ||
conditions: -> { where.not(status: STATUSES.values_at(:failed, :finished)) }, | ||
message: _('Cannot have multiple Jira imports running at the same time') | ||
} | ||
|
||
state_machine :status, initial: :initial do | ||
event :schedule do | ||
transition initial: :scheduled | ||
end | ||
|
||
event :start do | ||
transition scheduled: :started | ||
end | ||
|
||
event :finish do | ||
transition started: :finished | ||
end | ||
|
||
event :do_fail do | ||
transition [:initial, :scheduled, :started] => :failed | ||
end | ||
|
||
after_transition initial: :scheduled do |state, _| | ||
state.run_after_commit do | ||
job_id = Gitlab::JiraImport::Stage::StartImportWorker.perform_async(project.id) | ||
state.update(jid: job_id) if job_id | ||
end | ||
end | ||
|
||
after_transition any => :finished do |state, _| | ||
if state.jid.present? | ||
Gitlab::SidekiqStatus.unset(state.jid) | ||
|
||
state.update_column(:jid, nil) | ||
end | ||
end | ||
|
||
# Supress warning: | ||
# both JiraImportState and its :status machine have defined a different default for "status". | ||
# although both have same value but represented in 2 ways: integer(0) and symbol(:initial) | ||
def owner_class_attribute_default | ||
'initial' | ||
end | ||
end | ||
|
||
enum status: STATUSES | ||
|
||
def in_progress? | ||
scheduled? || started? | ||
end | ||
|
||
def refresh_jid_expiration | ||
return unless jid | ||
|
||
Gitlab::SidekiqStatus.set(jid, StuckImportJobsWorker::IMPORT_JOBS_EXPIRATION) | ||
end | ||
|
||
def self.jid_by(project_id:, status:) | ||
select(:jid).with_status(status).find_by(project_id: project_id) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.