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

Fail Jobs that don't decode as expected #101

Merged
merged 5 commits into from
Apr 10, 2024
Merged

Fail Jobs that don't decode as expected #101

merged 5 commits into from
Apr 10, 2024

Conversation

pbrisbin
Copy link
Member

@pbrisbin pbrisbin commented Apr 9, 2024

Originally, this decoding failure would enter the Left case and only
log the error. The Job would hang, neither ACKed nor FAILed until
its reservation expired.

Now, as long as it is valid JSON, we reach the Right-Just branch and
attempt to decode it further there. This way, if it can't decode, that
exception occurs in the right place to FAIL the job, as desired.

Closes #88.

@pbrisbin pbrisbin changed the title pb/fail on json 2 Fail Jobs that don't decode as expected Apr 9, 2024
pbrisbin added 4 commits April 9, 2024 13:48
This may be generally useful, but the immediate need is it will allow us
to test some behavior around it, which we are about to improve.
Originally, this decoding failure would enter the `Left` case and only
log the error. The Job would hang, neither `ACK`ed nor `FAIL`ed until
its reservation expired.

Now, as long as it is valid JSON, we reach the `Right`-`Just` branch and
attempt to decode it further there. This way, if it can't decode, that
exception occurs in the right place to `FAIL` the job, as desired.

Closes #88.
@pbrisbin pbrisbin force-pushed the pb/fail-on-json-2 branch from 5a3289e to f2d8d61 Compare April 9, 2024 17:49
@pbrisbin pbrisbin requested a review from z0isch April 9, 2024 17:51
@pbrisbin pbrisbin marked this pull request as ready for review April 9, 2024 17:51
@pbrisbin pbrisbin enabled auto-merge (rebase) April 9, 2024 17:54
-- | <https://github.com/contribsys/faktory/wiki/Worker-Lifecycle#heartbeat>
heartBeat :: Client -> WorkerId -> IO ()
heartBeat client workerId = do
threadDelaySeconds 25
command_ client "BEAT" [encode $ BeatPayload workerId]

fetchJob
:: FromJSON args => Client -> Queue -> IO (Either String (Maybe (Job args)))
fetchJob :: Client -> Queue -> IO (Either String (Maybe (Job Value)))
Copy link
Contributor

Choose a reason for hiding this comment

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

So commandJSON will parse to Value and then we parse it again in decodeJob to the type we are expecting?

Why this route instead of logging and throwing the err in https://github.com/freckle/faktory_worker_haskell/pull/101/files#diff-ac403ab2ca059ce5c79709e5f3fb294cb32ba3260b17fb4c21e185653ec747c9R107 ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah I see, I guess we don't have a job to processAndAck in that case

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess we don't have a job to processAndAck in that case

Exactly. There were some more details about that in the linked Issue:

When we FETCH to Job SomeAppType, if the args don't parse as SomeAppType, we don't even get back the Job part. Without that, we don't know the jid and can't report the FAIL. To Faktory, the Job was consumed and is in-progress -- until the reservation expiry.

@pbrisbin pbrisbin merged commit 9b519fd into main Apr 10, 2024
9 checks passed
@pbrisbin pbrisbin deleted the pb/fail-on-json-2 branch April 10, 2024 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Failure to parse payload doesn't report a FAIL
2 participants