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

Refactor to exceptions #31

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Refactor to exceptions #31

wants to merge 4 commits into from

Conversation

emhoracek
Copy link
Member

@emhoracek emhoracek commented Jan 24, 2017

Tests currently pass, but still some work to do. Would appreciate comments, suggestions.

It seems like I ought to be able to pull out the "log and comment" parts of the exception handling into a function, but I'm not sure how yet.

I like that the parts that are throwing exceptions seem much simpler now, but all the complexity is just being offloaded to the Fills. :/

Biggest problem is that I made this CacheInProgress exception that the retry function catches, but I'm not actually throwing it in the mutex function yet. So still need to figure that out.

@@ -204,7 +206,7 @@ clearRedisCache ctxt = R.runRedis (_redis ctxt) (rdelstar "wordpress:*")

unobj :: Value -> Object
unobj (Object x) = x
unobj _ = error "Not an object"
unobj _ = throw NotAnObject
Copy link
Member Author

Choose a reason for hiding this comment

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

this is silly, should've just stayed an error (it's only for testing)

("custom-endpoint-array", ctxt) `shouldRenderContaining` "2014-10-01"
("custom-endpoint-array", ctxt) `shouldRenderContaining` "2014-10-02"
("custom-endpoint-array", ctxt) `shouldRenderContaining` "2014-10-15"
it "should be able to reference fields from the custom endpoint in another custom endpoint query" $ do
("custom-endpoint-array", ctxt) `rendersSameAs` "custom-endpoint-enter-the-matrix"
it "should handle 404s without blowing up" $
("custom-endpoint-404", ctxt) `shouldRenderContaining` "404"
Copy link
Member Author

Choose a reason for hiding this comment

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

This works, but the wreq/http-client exception has a LOT of information that doesn't belong in the HTML debugging comment. Right now all the information about the request is in there.

where getAndCache = do jsonBlob <- wpRequest wpKey
wpCacheSet wpKey jsonBlob
stopReqMutex wpKey
return jsonBlob
Copy link
Member Author

Choose a reason for hiding this comment

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

this is so much easier to look at! yay!

Choose a reason for hiding this comment

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

👍 👍


errorUnless :: Text -> IO (CacheResult a) -> IO (Either StatusCode a)
catch action (\(e :: CacheInProgress) -> CC.threadDelay 100000 >> retryUnless action)

Copy link
Member Author

Choose a reason for hiding this comment

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

So here I'm caching this CacheInProgress exception, but I'm not actually throwing it in startMutex yet

(There are no tests that exercise this stuff!)

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.

2 participants