Skip to content
This repository has been archived by the owner on Sep 6, 2022. It is now read-only.

Commit

Permalink
Sleep before nacking (#22)
Browse files Browse the repository at this point in the history
Co-authored-by: Axel Hellström <[email protected]>
Co-authored-by: Frida Jakobsson <[email protected]>
  • Loading branch information
3 people authored May 26, 2020
1 parent 129b76c commit e81f7d1
Show file tree
Hide file tree
Showing 47 changed files with 3,257 additions and 137 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
version: 2.0
jobs:
build:
machine:
enabled: true
docker:
- image: circleci/node:12
working_directory: ~/insurello
steps:
- checkout
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
node_modules/
package-lock.json
src/*.js
dist/test
5 changes: 5 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extension": ["ts"],
"spec": "test/*_test.ts",
"require": "ts-node/register"
}
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
1 change: 1 addition & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ build: $(SRC)
$(BIN)/tsc --outDir dist --project . --pretty --declaration

lint: $(SRC)
$(BIN)/prettier -l $(SRC) $(TEST)
$(BIN)/prettier --check .
$(BIN)/tslint --project . --format codeFrame

format: $(SRC)
Expand Down
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ If the `event` field is a string instead of a callback function it is interprete
```typescript
mq.events({
type: commit.decoder,
init: options => ({}),
init: (options) => ({}),
event: "event",
events: {
claim: (commit: Commit, context) => Promise.resolve(),
closed: (commit: Commit, context) => Promise.resolve(),
rejected: (commit: Commit, context) => Promise.resolve()
}
rejected: (commit: Commit, context) => Promise.resolve(),
},
});
```
Expand All @@ -56,10 +56,10 @@ import * as t from "io-ts";

const helloWorld = mq.service({
type: t.type({ message: t.string }),
init: options => ({}),
init: (options) => ({}),
authorized: (headers, context) => Promise.resolve(context),
forbidden: (headers, context) => Promise.resolve(context),
response: context => Promise.resolve({ message: "Hello World!" })
response: (context) => Promise.resolve({ message: "Hello World!" }),
});
```
Expand All @@ -81,3 +81,11 @@ const helloName = mq.resource({
response: context => Promise.resolve({ message: `Hello ${context.name}!`` })
});
```

## Nack delay

By default, all handler types sleep for 30 seconds before nacking, to reduce the number of errors reported.

You can pass for example `defaultNackDelayMs: 10000` to `mq.events`, `mq.service` and `mq.resource` to change the default nack delay.

You can also set `.nackDelayMs = 0` on specific `Error`s to set a different delay for a certain error.
1 change: 1 addition & 0 deletions dist/src/decoder.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/src/decoder.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion dist/src/errors.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Logger } from "./logger";
import { Request } from "./request";
export interface ErrorDescription {
error: string;
error_description: string;
}
export declare const errorHandler: (req: Request, logger: import("winston").Logger) => (err?: unknown) => void;
export declare const errorHandler: (req: Request, logger: Logger, defaultDelayMs?: number) => (err?: unknown) => Promise<void>;
16 changes: 12 additions & 4 deletions dist/src/errors.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/src/errors.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions dist/src/events.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface SingleCallbackStyle<T, C, O> {
init: (options: any) => PromiseLike<C> | C;
event: Callback<T, C>;
logger?: Logger;
defaultNackDelayMs?: number;
}
interface EventCallbackStyle<T, C, O> {
type: t.Type<T, O>;
Expand All @@ -17,6 +18,7 @@ interface EventCallbackStyle<T, C, O> {
[key: string]: Callback<T, C>;
};
logger?: Logger;
defaultNackDelayMs?: number;
}
export declare const events: <T, C = any, O = T>(desc: Events<T, C, O>) => (options: any) => (req: Request) => Promise<void>;
export {};
7 changes: 4 additions & 3 deletions dist/src/events.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/src/events.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions dist/src/logger.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/src/logger.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/src/mq.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/src/mq.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion dist/src/request.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/src/request.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/src/resource.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ export interface Resource<T, U, C, TO, UO> {
update: (data: T, context: C) => PromiseLike<C> | C;
response: (context: C) => PromiseLike<U> | U;
logger?: Logger;
defaultNackDelayMs?: number;
}
export declare const resource: <T, U = unknown, C = any, TO = T, UO = U>(desc: Resource<T, U, C, TO, UO>) => (options: any) => (req: Request) => Promise<void>;
Loading

0 comments on commit e81f7d1

Please sign in to comment.