Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PaymentServer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Administrator
PaymentServer
Commits
c5240ad3
Unverified
Commit
c5240ad3
authored
4 years ago
by
Jean-Paul Calderone
Browse files
Options
Downloads
Patches
Plain Diff
Take a shot at this with the `retrying` function
parent
b8e4f86a
Branches
Branches containing commit
No related tags found
1 merge request
!62
Delayed redemption response
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
PaymentServer.cabal
+1
-0
1 addition, 0 deletions
PaymentServer.cabal
nix/PaymentServer.nix
+1
-0
1 addition, 0 deletions
nix/PaymentServer.nix
src/PaymentServer/Redemption.hs
+28
-1
28 additions, 1 deletion
src/PaymentServer/Redemption.hs
with
30 additions
and
1 deletion
PaymentServer.cabal
+
1
−
0
View file @
c5240ad3
...
...
@@ -42,6 +42,7 @@ library
, containers
, cryptonite
, sqlite-simple
, retry
default-language: Haskell2010
ghc-options: -Wmissing-import-lists -Wunused-imports
pkgconfig-depends: libchallenge_bypass_ristretto_ffi
...
...
This diff is collapsed.
Click to expand it.
nix/PaymentServer.nix
+
1
−
0
View file @
c5240ad3
...
...
@@ -76,6 +76,7 @@ in { system, compiler, flags, pkgs, hsPkgs, pkgconfPkgs, ... }:
(
hsPkgs
.
"containers"
or
(
buildDepError
"containers"
))
(
hsPkgs
.
"cryptonite"
or
(
buildDepError
"cryptonite"
))
(
hsPkgs
.
"sqlite-simple"
or
(
buildDepError
"sqlite-simple"
))
(
hsPkgs
.
"retry"
or
(
buildDepError
"retry"
))
];
pkgconfig
=
[
(
pkgconfPkgs
.
"libchallenge_bypass_ristretto_ffi"
or
(
pkgConfDepError
"libchallenge_bypass_ristretto_ffi"
))
...
...
This diff is collapsed.
Click to expand it.
src/PaymentServer/Redemption.hs
+
28
−
1
View file @
c5240ad3
...
...
@@ -14,6 +14,13 @@ module PaymentServer.Redemption
import
GHC.Generics
(
Generic
)
import
Control.Retry
(
retrying
,
constantDelay
,
limitRetries
)
import
Control.Monad.IO.Class
(
liftIO
)
...
...
@@ -155,6 +162,25 @@ jsonErr400 reason = err400
redemptionServer
::
VoucherDatabase
d
=>
Issuer
->
d
->
Server
RedemptionAPI
redemptionServer
=
redeem
-- | Try an operation repeatedly for several minutes with a brief delay
-- between tries.
retry
::
IO
(
Either
RedeemError
()
)
->
IO
(
Either
RedeemError
()
)
retry
op
=
retrying
policy
shouldRetry
(
\
_
->
op
)
where
-- Total duration for which to retry in milliseconds.
totalRetryDuration
=
3
*
60
*
1000
-- Time to delay between each try in milliseconds.
perRetryDelay
=
500
-- Limit on the number of retries.
numRetries
=
totalRetryDuration
`
div
`
totalRetryDuration
policy
=
constantDelay
(
perRetryDelay
*
1000
)
<>
limitRetries
numRetries
shouldRetry
status
value
=
case
value
of
Left
NotPaid
->
return
True
_
->
return
False
-- | Handler for redemption requests. Use the database to try to redeem the
-- voucher and return signatures. Return a failure if this is not possible
-- (eg because the voucher was already redeemed).
...
...
@@ -163,8 +189,9 @@ redeem issue database (Redeem voucher tokens counter) =
if
counter
<
0
||
counter
>=
maxCounter
then
throwError
$
jsonErr400
(
CounterOutOfBounds
0
maxCounter
counter
)
else
do
let
fingerprint
=
fingerprintFromTokens
tokens
result
<-
liftIO
$
redeemVoucherWithCounter
database
voucher
fingerprint
counter
result
<-
liftIO
.
retry
$
redeemVoucherWithCounter
database
voucher
fingerprint
counter
case
result
of
Left
NotPaid
->
do
throwError
$
jsonErr400
Unpaid
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment