Skip to content
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

add component and params to Error on visibility timeout #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,19 @@ module.exports = opts => {
typeof handlers[type] === 'function' ? handlers[type] : missing(type)

const processJob = ({ type, payload }, callback) => {

const done = once(callback)
details = mergeAll([ options, { type, payload }, timeoutErr ]),
logTimeout = partial(timeoutLogger, [ details ]),
handleTimeout = compose(partial(done, [ new Error(timeoutErr.error) ]), tap(logTimeout))
timeout = setTimeout(handleTimeout, visibilityTimeout * 1000),
finish = compose(tap(partial(clearTimeout, [ timeout ])), done)
const done = once(callback)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit-pick: leftover extra spaces


const handleTimeout = () => {
const error = new Error(timeoutErr.error)
const params = mergeAll([ options, { type, payload }, timeoutErr ])
error.params = params
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Combine this with the previous line?

error.component = 'squiss-jobs'
timeoutLogger(params)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there's a params in scope at this point...which is probably my fault for suggesting you combine those two lines earlier where iirc, you had a separate const params = ....

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm not seeing any params anywhere. Do we have linting for this library?

done(error)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not saying it's any clearer, but is it worth making this a pipe?

const logTimeout = partial(timeoutLogger, [ params ])
const handleTimeout = pipe(
  always(new Error(timeoutErr.error)),
  addErrorContext,
  tap(logTimeout),
  complete
)


const timeout = setTimeout(handleTimeout, visibilityTimeout * 1000),
finish = compose(tap(partial(clearTimeout, [ timeout ])), done)

return Promise.resolve(payload)
.then(handlerFor(type))
Expand Down