-
Notifications
You must be signed in to change notification settings - Fork 447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(events-producer): serialize and deserialize custom events #2987
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import { | |
array2obj, | ||
clientCommandMessageReg, | ||
isRedisInstance, | ||
parseObjectValues, | ||
QUEUE_EVENT_SUFFIX, | ||
} from '../utils'; | ||
import { QueueBase } from './queue-base'; | ||
|
@@ -298,20 +299,40 @@ export class QueueEvents extends QueueBase { | |
id = events[i][0]; | ||
const args = array2obj(events[i][1]); | ||
|
||
let { event, ...restArgs } = args; | ||
|
||
// | ||
// TODO: we may need to have a separate xtream for progress data | ||
// to avoid this hack. | ||
switch (args.event) { | ||
switch (event) { | ||
case 'active': | ||
case 'added': | ||
case 'cleaned': | ||
case 'debounced': // TODO: to be removed in next breaking change | ||
case 'deduplicated': | ||
case 'delayed': | ||
case 'duplicated': | ||
case 'error': | ||
case 'failed': | ||
case 'paused': | ||
case 'removed': | ||
case 'resumed': | ||
case 'retries-exhausted': | ||
case 'stalled': | ||
case 'waiting': | ||
case 'waiting-children': | ||
break; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. avoid to do a deserialization for these events that do not need it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fastest here would be to use a Set object that is global for this module and that provides fast check for membership. |
||
case 'progress': | ||
args.data = JSON.parse(args.data); | ||
restArgs.data = JSON.parse(restArgs.data); | ||
break; | ||
case 'completed': | ||
args.returnvalue = JSON.parse(args.returnvalue); | ||
restArgs.returnvalue = JSON.parse(restArgs.returnvalue); | ||
break; | ||
default: | ||
restArgs = parseObjectValues(restArgs); | ||
break; | ||
} | ||
|
||
const { event, ...restArgs } = args; | ||
|
||
if (event === 'drained') { | ||
this.emit(event, id); | ||
} else { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we are digging ourselves more into this rabbit hole, as it would have been much simpler to just allow sending strings as payloads for the custom events and let the user serialize and deserialise as they see fit, this will never be satisfactory for all cases out there...