Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
e2c3cc8f
Commit
e2c3cc8f
authored
Oct 13, 2020
by
Sean Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move apply incident label into worker
- Add worker & update queues file
parent
c82d8413
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
29 additions
and
15 deletions
+29
-15
ee/app/models/issuable_sla.rb
ee/app/models/issuable_sla.rb
+1
-1
ee/app/workers/all_queues.yml
ee/app/workers/all_queues.yml
+8
-0
ee/app/workers/incident_management/apply_incident_sla_exceeded_label_worker.rb
...nt_management/apply_incident_sla_exceeded_label_worker.rb
+12
-8
ee/app/workers/incident_management/incident_sla_exceeded_check_worker.rb
...incident_management/incident_sla_exceeded_check_worker.rb
+2
-2
ee/spec/workers/incident_management/apply_incident_sla_exceeded_label_worker_spec.rb
...nagement/apply_incident_sla_exceeded_label_worker_spec.rb
+6
-4
No files found.
ee/app/models/issuable_sla.rb
View file @
e2c3cc8f
...
...
@@ -4,5 +4,5 @@ class IssuableSla < ApplicationRecord
belongs_to
:issue
,
optional:
false
validates
:due_at
,
presence:
true
scope
:exceeded_for_issues
,
->
{
join
s
(
:issue
).
merge
(
Issue
.
opened
).
where
(
'due_at < ?'
,
Time
.
current
)
}
scope
:exceeded_for_issues
,
->
{
include
s
(
:issue
).
merge
(
Issue
.
opened
).
where
(
'due_at < ?'
,
Time
.
current
)
}
end
ee/app/workers/all_queues.yml
View file @
e2c3cc8f
...
...
@@ -661,6 +661,14 @@
:weight:
1
:idempotent:
:tags: []
-
:name: incident_management_apply_incident_sla_exceeded_label
:feature_category: :incident_management
:has_external_dependencies:
:urgency: :low
:resource_boundary: :unknown
:weight:
1
:idempotent:
true
:tags: []
-
:name: ldap_group_sync
:feature_category: :authentication_and_authorization
:has_external_dependencies:
true
...
...
ee/app/
services/incident_management/apply_incident_sla_exceeded_label_service
.rb
→
ee/app/
workers/incident_management/apply_incident_sla_exceeded_label_worker
.rb
View file @
e2c3cc8f
# frozen_string_literal: true
module
IncidentManagement
class
ApplyIncidentSlaExceededLabelService
<
BaseService
def
initialize
(
incident
)
super
(
incident
.
project
)
class
ApplyIncidentSlaExceededLabelWorker
include
ApplicationWorker
@incident
=
incident
@label
=
incident_exceeded_sla_label
end
idempotent!
feature_category
:incident_management
def
perform
(
incident_id
)
@incident
=
Issue
.
find_by
(
id:
incident_id
)
@project
=
incident
&
.
project
def
execute
return
unless
incident
&&
project
@label
=
incident_exceeded_sla_label
return
if
incident
.
label_ids
.
include?
(
label
.
id
)
incident
.
labels
<<
label
...
...
@@ -20,7 +24,7 @@ module IncidentManagement
private
attr_reader
:incident
,
:label
attr_reader
:incident
,
:
project
,
:
label
def
add_resource_event
ResourceEvents
::
ChangeLabelsService
...
...
ee/app/workers/incident_management/incident_sla_exceeded_check_worker.rb
View file @
e2c3cc8f
# frozen_string_literal: true
module
IncidentManagement
class
IncidentSlaExceededCheckWorker
# rubocop:disable Scalability/IdempotentWorker
class
IncidentSlaExceededCheckWorker
include
ApplicationWorker
include
CronjobQueue
# rubocop:disable Scalability/CronWorkerContext
...
...
@@ -11,7 +11,7 @@ module IncidentManagement
def
perform
IssuableSla
.
exceeded_for_issues
.
find_in_batches
do
|
incident_slas
|
incident_slas
.
each
do
|
incident_sla
|
ApplyIncidentSlaExceededLabel
Service
.
new
(
incident_sla
.
issue
).
execute
ApplyIncidentSlaExceededLabel
Worker
.
perform_async
(
incident_sla
.
issue
.
id
)
rescue
StandardError
=>
e
Gitlab
::
AppLogger
.
error
(
"Error encountered in
#{
self
.
class
.
name
}
:
#{
e
}
"
)
...
...
ee/spec/
services/incident_management/apply_incident_sla_exceeded_label_service
_spec.rb
→
ee/spec/
workers/incident_management/apply_incident_sla_exceeded_label_worker
_spec.rb
View file @
e2c3cc8f
...
...
@@ -2,7 +2,9 @@
require
'spec_helper'
RSpec
.
describe
IncidentManagement
::
ApplyIncidentSlaExceededLabelService
do
RSpec
.
describe
IncidentManagement
::
ApplyIncidentSlaExceededLabelWorker
do
let
(
:worker
)
{
described_class
.
new
}
let_it_be_with_refind
(
:incident
)
{
create
(
:incident
)
}
let_it_be
(
:project
)
{
incident
.
project
}
let_it_be
(
:label
)
do
...
...
@@ -12,7 +14,7 @@ RSpec.describe IncidentManagement::ApplyIncidentSlaExceededLabelService do
.
payload
[
:label
]
end
subject
(
:
apply_label
)
{
described_class
.
new
(
incident
).
execute
}
subject
(
:
perform
)
{
worker
.
perform
(
incident
.
id
)
}
context
'label exists already'
do
before
do
...
...
@@ -25,11 +27,11 @@ RSpec.describe IncidentManagement::ApplyIncidentSlaExceededLabelService do
end
it
'adds a label to the incident'
do
expect
{
apply_label
}.
to
change
{
incident
.
labels
.
reload
.
count
}.
by
(
1
)
expect
{
perform
}.
to
change
{
incident
.
labels
.
reload
.
count
}.
by
(
1
)
expected_props
=
IncidentManagement
::
CreateIncidentSlaExceededLabelService
::
LABEL_PROPERTIES
expect
(
apply_label
).
to
have_attributes
(
expected_props
)
expect
(
perform
).
to
have_attributes
(
expected_props
)
end
it
'adds a note that the label was added'
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment