-
Notifications
You must be signed in to change notification settings - Fork 6
Queues via BullMQ #3647
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
Merged
Queues via BullMQ #3647
Changes from 17 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
059dc2c
Queues via BullMQ
CarsonF 4d328f4
Support in memory BullMQ via heavily patched ioredis-mock
CarsonF bb7dc1a
Better fix the job id incr type mismatch
CarsonF 88d4f5b
Add queue name to the collapsed Job inspection
CarsonF 414fa59
Fix the mock Redis' handling of BullMQ's `getRanges` & `getCounts` sc…
CarsonF 8fce2c8
Fix mock handling of Job.getState with delayed jobs
CarsonF 491851d
Only require manual queue worker registration if using real Redis con…
CarsonF 8ebd155
Declare Duration scalar
CarsonF 157ecf1
Expose queue states to GQL
CarsonF 410aba6
Add GQL mutations for Queue/Job actions
CarsonF 9e06ace
Add JMES path searching to Job JSON fields
CarsonF 1f30dfc
Declare queue enums
CarsonF 695258a
Add a JMES path filter for the `Queue.jobs` list
CarsonF 9477427
Replace `Job.stacktrace[]` with `Job.failures[][]`
CarsonF a27e11f
Refactor exception stack formatting
CarsonF 0aa52f6
Fix windows path conversion
CarsonF 5d67a1f
Clean up job error stacks like we do for logging
CarsonF b8f4648
Port two delay calc functions
CarsonF 8fe781a
Fix Lua integer check to match engine
CarsonF File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,29 @@ | ||
| diff --git a/lib/index.js b/lib/index.js | ||
| index a82c2975d19bfcce4179d27594e26e0c47ef7a1f..2587c1b714d3b11bb52bfd708f4cb256dc511859 100644 | ||
| --- a/lib/index.js | ||
| +++ b/lib/index.js | ||
| @@ -3824,7 +3824,7 @@ var { lua: lua2, to_luastring: toLuaString2 } = import_fengari2.default, defineR | ||
| let rawArgs = vm.extractArgs(), returnError = rawArgs[0], result; | ||
| try { | ||
| let args = rawArgs.slice(1), name = args[0].toLowerCase(); | ||
| - result = commands_exports[name].bind(this)(...args.slice(1)), name === "hgetall" && (result = [].concat(...Object.entries(result))); | ||
| + result = this.luaCommands[name].call(this, ...args.slice(1)), name === "hgetall" && (result = [].concat(...Object.entries(result))); | ||
| } catch (err) { | ||
| if (!returnError) | ||
| throw err; | ||
| @@ -3845,6 +3845,7 @@ function defineArgv(vm, numberOfKeys, commandArgs) { | ||
| var customCommand = (numberOfKeys, luaCode) => function(...luaScriptArgs) { | ||
| let vm = init(); | ||
| defineRedisObject(vm)(callToRedisCommand(vm).bind(this)), defineKeys.bind(this)(vm, numberOfKeys, luaScriptArgs), defineArgv.bind(this)(vm, numberOfKeys, luaScriptArgs); | ||
| + this.vmInit?.(vm); | ||
| let topBeforeExecute = lua2.lua_gettop(vm.L); | ||
| vm.luaExecString(luaCode); | ||
| let retVal = vm.popReturnValue(topBeforeExecute); | ||
| @@ -6243,6 +6244,7 @@ var defaultOptions = { | ||
| removeFrom(this.channels), removeFrom(this.patternChannels); | ||
| } | ||
| _initCommands() { | ||
| + this.luaCommands = { ...commands_exports }; | ||
| Object.keys(commands_exports).forEach((command3) => { | ||
| let commandName = command3 === "evaluate" ? "eval" : command3; | ||
| this[commandName] = command( |
This file contains hidden or 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 hidden or 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 hidden or 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,9 @@ | ||
| export function getCauseList(ex: Error, includeSelf = true): readonly Error[] { | ||
| const previous: Error[] = includeSelf ? [ex] : []; | ||
| let current = ex; | ||
| while (current.cause instanceof Error) { | ||
| current = current.cause; | ||
| previous.push(current); | ||
| } | ||
| return previous; | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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,18 @@ | ||
| import type { Type } from '@nestjs/common'; | ||
| import { Field, type FieldOptions, type ReturnTypeFunc } from '@nestjs/graphql'; | ||
| import { entries } from '@seedcompany/common'; | ||
|
|
||
| /** | ||
| * A helper to declare @Field decorators externally | ||
| */ | ||
| export const declareGqlFields = <T>( | ||
| obj: Type<T>, | ||
| fields: { [_ in keyof T]?: FieldOptions & { type: ReturnTypeFunc } }, | ||
| ) => { | ||
| for (const [name, val] of entries(fields)) { | ||
| if (val) { | ||
| const { type, ...options } = val; | ||
| Field(type, options as FieldOptions)(obj.prototype, name); | ||
| } | ||
| } | ||
| }; |
This file contains hidden or 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,75 @@ | ||
| import { type CustomScalar, Scalar } from '@nestjs/graphql'; | ||
| import { mapEntries, type Nil } from '@seedcompany/common'; | ||
| import type { DurationIn } from '@seedcompany/common/temporal/luxon'; | ||
| import { stripIndent } from 'common-tags'; | ||
| import { GraphQLError, Kind, type ValueNode } from 'graphql'; | ||
| import { GraphQLDuration } from 'graphql-scalars'; | ||
| import { Duration } from 'luxon'; | ||
|
|
||
| @Scalar('Duration', () => Duration) | ||
| export class DurationScalar implements CustomScalar<string, DurationIn | null> { | ||
| description = ( | ||
| stripIndent(GraphQLDuration.description!) + | ||
| '\n' + | ||
| stripIndent` | ||
| For inputs, ISO strings are accepted, but also many other forms: | ||
| An integer/float can be used to specify in milliseconds. | ||
| An object declaring numeric values for each unit: \`{ days: 2 }\` | ||
| Or a human-readable string: \`"1 day 5 hours 3 mins 2s"\` | ||
| ` | ||
| ).replaceAll(/\n(?!\n)/g, '\n\n'); | ||
|
|
||
| parseLiteral(ast: ValueNode, variables: Record<string, unknown> | Nil) { | ||
| if (ast.kind === Kind.NULL) { | ||
| return null; // idk if this is necessary | ||
| } | ||
| if ( | ||
| ast.kind === Kind.STRING || | ||
| ast.kind === Kind.FLOAT || | ||
| ast.kind === Kind.INT | ||
| ) { | ||
| return Duration.from(ast.value); | ||
CarsonF marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| if (ast.kind === Kind.OBJECT) { | ||
| return Duration.fromObject( | ||
| Object.fromEntries( | ||
| mapEntries(ast.fields, ({ name: { value: name }, value }) => { | ||
| if ( | ||
| value.kind !== Kind.INT && | ||
| value.kind !== Kind.FLOAT && | ||
| value.kind !== Kind.VARIABLE | ||
| ) { | ||
| throw new GraphQLError( | ||
| `Duration object literals can only have numeric values for each unit`, | ||
| ); | ||
| } | ||
| const parsed = | ||
| value.kind === Kind.VARIABLE | ||
| ? variables?.[value.name.value] | ||
| : parseFloat(value.value); | ||
|
|
||
| return [name, parsed]; | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }), | ||
| ), | ||
| ); | ||
| } | ||
|
|
||
| throw new GraphQLError(`Durations cannot be parsed as: ${ast.kind}`); | ||
| } | ||
|
|
||
| parseValue(value: any) { | ||
| return Duration.from(value); | ||
| } | ||
|
|
||
| serialize(value: unknown) { | ||
| if (Duration.isDuration(value)) { | ||
| return value.toISO(); | ||
| } | ||
| if (typeof value === 'string') { | ||
| return value; | ||
| } | ||
| throw new GraphQLError( | ||
| 'Expected a Duration but received a: ' + typeof value, | ||
| ); | ||
| } | ||
CarsonF marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
This file contains hidden or 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 hidden or 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,26 @@ | ||
| import { search } from '@aws-lambda-powertools/jmespath'; | ||
| import { stripIndent } from 'common-tags'; | ||
| import { GraphQLError, GraphQLScalarType, GraphQLString } from 'graphql'; | ||
|
|
||
| const base = GraphQLString.toConfig(); | ||
| export const JmesPathScalar = new GraphQLScalarType({ | ||
| ...base, | ||
| name: 'JMESPath', | ||
| description: stripIndent` | ||
| A JMESPath expression. | ||
|
|
||
| See https://jmespath.org/ for details | ||
| `, | ||
| specifiedByURL: 'https://jmespath.org/specification.html', | ||
| parseLiteral: (node) => validate(base.parseLiteral(node)), | ||
| parseValue: (value) => validate(base.parseValue(value)), | ||
| }); | ||
|
|
||
| const validate = (value: string) => { | ||
| try { | ||
| search(value, {}); | ||
| } catch (e) { | ||
| throw new GraphQLError((e as Error).message.replaceAll(/"/g, '`')); | ||
| } | ||
| return value; | ||
| }; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,3 +1,2 @@ | ||
| export * from './is-src-frame'; | ||
| export * from './normalize-frame-path'; | ||
| export * from './pretty-stack'; | ||
| export * from './jest-skip-source-file'; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.