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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
8dd3dc18
Commit
8dd3dc18
authored
Feb 05, 2019
by
Peter Leitzen
Committed by
Sean McGivern
Feb 05, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make `ActionContorller::Parameters` serializable for sidekiq jobs
parent
97041bb6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
79 additions
and
6 deletions
+79
-6
app/workers/mail_scheduler/notification_service_worker.rb
app/workers/mail_scheduler/notification_service_worker.rb
+30
-1
changelogs/unreleased/pl-serialize-ac-parameters.yml
changelogs/unreleased/pl-serialize-ac-parameters.yml
+5
-0
spec/workers/mail_scheduler/notification_service_worker_spec.rb
...orkers/mail_scheduler/notification_service_worker_spec.rb
+44
-5
No files found.
app/workers/mail_scheduler/notification_service_worker.rb
View file @
8dd3dc18
...
@@ -23,7 +23,7 @@ module MailScheduler
...
@@ -23,7 +23,7 @@ module MailScheduler
end
end
def
self
.
perform_async
(
*
args
)
def
self
.
perform_async
(
*
args
)
super
(
*
A
ctiveJob
::
A
rguments
.
serialize
(
args
))
super
(
*
Arguments
.
serialize
(
args
))
end
end
private
private
...
@@ -38,5 +38,34 @@ module MailScheduler
...
@@ -38,5 +38,34 @@ module MailScheduler
end
end
end
end
end
end
# Permit ActionController::Parameters for serializable Hash
#
# Port of
# https://github.com/rails/rails/commit/945fdd76925c9f615bf016717c4c8db2b2955357#diff-fc90ec41ef75be8b2259526fe1a8b663
module
Arguments
include
ActiveJob
::
Arguments
extend
self
private
def
serialize_argument
(
argument
)
case
argument
when
->
(
arg
)
{
arg
.
respond_to?
(
:permitted?
)
}
serialize_hash
(
argument
.
to_h
).
tap
do
|
result
|
result
[
WITH_INDIFFERENT_ACCESS_KEY
]
=
serialize_argument
(
true
)
end
else
super
end
end
end
# Make sure we remove this patch starting with Rails 6.0.
if
Rails
.
version
.
start_with?
(
'6.0'
)
raise
<<~
MSG
Please remove the patch `Arguments` module and use `ActiveJob::Arguments` again.
MSG
end
end
end
end
end
changelogs/unreleased/pl-serialize-ac-parameters.yml
0 → 100644
View file @
8dd3dc18
---
title
:
Make `ActionController::Parameters` serializable for sidekiq jobs
merge_request
:
24864
author
:
type
:
fixed
spec/workers/mail_scheduler/notification_service_worker_spec.rb
View file @
8dd3dc18
...
@@ -9,6 +9,10 @@ describe MailScheduler::NotificationServiceWorker do
...
@@ -9,6 +9,10 @@ describe MailScheduler::NotificationServiceWorker do
ActiveJob
::
Arguments
.
serialize
(
args
)
ActiveJob
::
Arguments
.
serialize
(
args
)
end
end
def
deserialize
(
args
)
ActiveJob
::
Arguments
.
deserialize
(
args
)
end
describe
'#perform'
do
describe
'#perform'
do
it
'deserializes arguments from global IDs'
do
it
'deserializes arguments from global IDs'
do
expect
(
worker
.
notification_service
).
to
receive
(
method
).
with
(
key
)
expect
(
worker
.
notification_service
).
to
receive
(
method
).
with
(
key
)
...
@@ -42,13 +46,48 @@ describe MailScheduler::NotificationServiceWorker do
...
@@ -42,13 +46,48 @@ describe MailScheduler::NotificationServiceWorker do
end
end
end
end
describe
'.perform_async'
do
describe
'.perform_async'
,
:sidekiq
do
around
do
|
example
|
Sidekiq
::
Testing
.
fake!
{
example
.
run
}
end
it
'serializes arguments as global IDs when scheduling'
do
it
'serializes arguments as global IDs when scheduling'
do
Sidekiq
::
Testing
.
fake!
do
described_class
.
perform_async
(
method
,
key
)
described_class
.
perform_async
(
method
,
key
)
expect
(
described_class
.
jobs
.
count
).
to
eq
(
1
)
expect
(
described_class
.
jobs
.
first
).
to
include
(
'args'
=>
[
method
,
*
serialize
(
key
)])
end
context
'with ActiveController::Parameters'
do
let
(
:parameters
)
{
ActionController
::
Parameters
.
new
(
hash
)
}
let
(
:hash
)
do
{
"nested"
=>
{
"hash"
=>
true
}
}
end
context
'when permitted'
do
before
do
parameters
.
permit!
end
it
'serializes as a serializable Hash'
do
described_class
.
perform_async
(
method
,
parameters
)
expect
(
described_class
.
jobs
.
count
).
to
eq
(
1
)
expect
(
described_class
.
jobs
.
count
).
to
eq
(
1
)
expect
(
described_class
.
jobs
.
first
).
to
include
(
'args'
=>
[
method
,
*
serialize
(
key
)])
expect
(
deserialize
(
described_class
.
jobs
.
first
[
'args'
]))
.
to
eq
([
method
,
hash
])
end
end
context
'when not permitted'
do
it
'fails to serialize'
do
expect
{
described_class
.
perform_async
(
method
,
parameters
)
}
.
to
raise_error
(
ActionController
::
UnfilteredParameters
)
end
end
end
end
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