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
d48d879e
Commit
d48d879e
authored
Oct 13, 2016
by
Oswaldo Ferreira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Does not raise error when Note not found when processing NewNoteWorker
- Also remove unnecessary param
parent
6eeff67c
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
99 additions
and
11 deletions
+99
-11
app/models/note.rb
app/models/note.rb
+1
-0
app/services/notes/create_service.rb
app/services/notes/create_service.rb
+5
-2
app/workers/new_note_worker.rb
app/workers/new_note_worker.rb
+7
-5
changelogs/unreleased/new-note-worker-record-not-found-fix.yml
...elogs/unreleased/new-note-worker-record-not-found-fix.yml
+4
-0
spec/services/notes/create_service_spec.rb
spec/services/notes/create_service_spec.rb
+33
-4
spec/workers/new_note_worker_spec.rb
spec/workers/new_note_worker_spec.rb
+49
-0
No files found.
app/models/note.rb
View file @
d48d879e
...
...
@@ -7,6 +7,7 @@ class Note < ActiveRecord::Base
include
Importable
include
FasterCacheKeys
include
CacheMarkdownField
include
AfterCommitQueue
cache_markdown_field
:note
,
pipeline: :note
...
...
app/services/notes/create_service.rb
View file @
d48d879e
...
...
@@ -26,9 +26,12 @@ module Notes
note
.
note
=
content
end
if
!
only_commands
&&
note
.
save
note
.
run_after_commit
do
# Finish the harder work in the background
NewNoteWorker
.
perform_in
(
2
.
seconds
,
note
.
id
,
params
)
NewNoteWorker
.
perform_async
(
note
.
id
)
end
if
!
only_commands
&&
note
.
save
todo_service
.
new_note
(
note
,
current_user
)
end
...
...
app/workers/new_note_worker.rb
View file @
d48d879e
...
...
@@ -2,10 +2,12 @@ class NewNoteWorker
include
Sidekiq
::
Worker
include
DedicatedSidekiqQueue
def
perform
(
note_id
,
note_params
)
note
=
Note
.
find
(
note_id
)
NotificationService
.
new
.
new_note
(
note
)
Notes
::
PostProcessService
.
new
(
note
).
execute
def
perform
(
note_id
)
if
note
=
Note
.
find_by
(
id:
note_id
)
NotificationService
.
new
.
new_note
(
note
)
Notes
::
PostProcessService
.
new
(
note
).
execute
else
Rails
.
logger
.
error
(
"NewNoteWorker: couldn't find note with ID=
#{
note_id
}
, skipping job"
)
end
end
end
changelogs/unreleased/new-note-worker-record-not-found-fix.yml
0 → 100644
View file @
d48d879e
---
title
:
Fix record not found error on NewNoteWorker processing
merge_request
:
6863
author
:
Oswaldo Ferreira
spec/services/notes/create_service_spec.rb
View file @
d48d879e
...
...
@@ -14,12 +14,41 @@ describe Notes::CreateService, services: true do
end
context
"valid params"
do
before
do
@note
=
Notes
::
CreateService
.
new
(
project
,
user
,
opts
).
execute
it
'returns a valid note'
do
note
=
Notes
::
CreateService
.
new
(
project
,
user
,
opts
).
execute
expect
(
note
).
to
be_valid
end
it
'returns a persisted note'
do
note
=
Notes
::
CreateService
.
new
(
project
,
user
,
opts
).
execute
expect
(
note
).
to
be_persisted
end
it
'note has valid content'
do
note
=
Notes
::
CreateService
.
new
(
project
,
user
,
opts
).
execute
expect
(
note
.
note
).
to
eq
(
opts
[
:note
])
end
it
{
expect
(
@note
).
to
be_valid
}
it
{
expect
(
@note
.
note
).
to
eq
(
opts
[
:note
])
}
it
'TodoService#new_note is called'
do
note
=
build
(
:note
)
allow
(
project
).
to
receive_message_chain
(
:notes
,
:new
).
with
(
opts
)
{
note
}
expect_any_instance_of
(
TodoService
).
to
receive
(
:new_note
).
with
(
note
,
user
)
Notes
::
CreateService
.
new
(
project
,
user
,
opts
).
execute
end
it
'enqueues NewNoteWorker'
do
note
=
build
(
:note
,
id:
999
)
allow
(
project
).
to
receive_message_chain
(
:notes
,
:new
).
with
(
opts
)
{
note
}
expect
(
NewNoteWorker
).
to
receive
(
:perform_async
).
with
(
note
.
id
)
Notes
::
CreateService
.
new
(
project
,
user
,
opts
).
execute
end
end
describe
'note with commands'
do
...
...
spec/workers/new_note_worker_spec.rb
0 → 100644
View file @
d48d879e
require
"spec_helper"
describe
NewNoteWorker
do
context
'when Note found'
do
let
(
:note
)
{
create
(
:note
)
}
it
"calls NotificationService#new_note"
do
expect_any_instance_of
(
NotificationService
).
to
receive
(
:new_note
).
with
(
note
)
described_class
.
new
.
perform
(
note
.
id
)
end
it
"calls Notes::PostProcessService#execute"
do
notes_post_process_service
=
double
(
Notes
::
PostProcessService
)
allow
(
Notes
::
PostProcessService
).
to
receive
(
:new
).
with
(
note
)
{
notes_post_process_service
}
expect
(
notes_post_process_service
).
to
receive
(
:execute
)
described_class
.
new
.
perform
(
note
.
id
)
end
end
context
'when Note not found'
do
let
(
:unexistent_note_id
)
{
999
}
it
'logs NewNoteWorker process skipping'
do
expect
(
Rails
.
logger
).
to
receive
(
:error
).
with
(
"NewNoteWorker: couldn't find note with ID=999, skipping job"
)
described_class
.
new
.
perform
(
unexistent_note_id
)
end
it
'does not raise errors'
do
expect
{
described_class
.
new
.
perform
(
unexistent_note_id
)
}.
not_to
raise_error
end
it
"does not call NotificationService#new_note"
do
expect_any_instance_of
(
NotificationService
).
not_to
receive
(
:new_note
)
described_class
.
new
.
perform
(
unexistent_note_id
)
end
it
"does not call Notes::PostProcessService#execute"
do
expect_any_instance_of
(
Notes
::
PostProcessService
).
not_to
receive
(
:execute
)
described_class
.
new
.
perform
(
unexistent_note_id
)
end
end
end
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