powerqueue-sqs (empty) → 0.1.0.0
raw patch · 4 files changed
+128/−0 lines, 4 filesdep +aws-simpledep +basedep +powerqueuesetup-changed
Dependencies added: aws-simple, base, powerqueue, text, timespan
Files
- LICENSE +30/−0
- Setup.hs +2/−0
- powerqueue-sqs.cabal +29/−0
- src/Data/PowerQueue/Backend/SQS.hs +67/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Alexander Thiemann (c) 2017++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Alexander Thiemann nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ powerqueue-sqs.cabal view
@@ -0,0 +1,29 @@+name: powerqueue-sqs+version: 0.1.0.0+synopsis: A Amazon SQS backend for powerqueue+description: A Amazon SQS backend for powerqueue+homepage: https://github.com/agrafix/powerqueue#readme+license: BSD3+license-file: LICENSE+author: Alexander Thiemann+maintainer: mail@athiemann.net+copyright: 2017 Alexander Thiemann <mail@athiemann.net>+category: Web+build-type: Simple+cabal-version: >=1.10++library+ hs-source-dirs: src+ exposed-modules:+ Data.PowerQueue.Backend.SQS+ build-depends:+ base >= 4.7 && < 5+ , powerqueue >= 0.2+ , aws-simple >= 0.4+ , text >= 1.2+ , timespan >= 0.3+ default-language: Haskell2010++source-repository head+ type: git+ location: https://github.com/agrafix/powerqueue
+ src/Data/PowerQueue/Backend/SQS.hs view
@@ -0,0 +1,67 @@+{-# LANGUAGE RankNTypes #-}+module Data.PowerQueue.Backend.SQS+ ( SqsConfig(..)+ , newSQSBackend+ )+where++import Data.PowerQueue+import Data.Time.TimeSpan+import Network.AWS.Simple+import qualified Control.Monad.Fail as Fail+import qualified Data.Text as T++data SqsConfig j+ = SqsConfig+ { sc_aws :: !AWSHandle+ , sc_queueName :: !T.Text+ , sc_writeJob :: j -> T.Text+ , sc_readJob :: forall m. Fail.MonadFail m => T.Text -> m j+ }++newSQSBackend :: SqsConfig j -> IO (QueueBackend j)+newSQSBackend cfg =+ do qu <- sqsGetQueue (sc_aws cfg) (sc_queueName cfg)+ pure $+ QueueBackend+ { qb_lift = id+ , qb_enqueue = enqueue cfg qu+ , qb_dequeue = dequeue cfg qu+ , qb_confirm = confirm cfg qu+ , qb_rollback = rollback cfg qu+ , qb_reportProgress = repProgress cfg qu+ , qb_progressReportInterval = seconds 40+ }++enqueue :: SqsConfig j -> AWSQueue -> j -> IO Bool+enqueue cfg q job =+ do sqsSendMessage (sc_aws cfg) q $ sc_writeJob cfg job+ pure True++dequeue :: SqsConfig j -> AWSQueue -> IO (MessageHandle, j)+dequeue cfg q =+ do let fetchLoop =+ do msgs <-+ sqsGetMessage (sc_aws cfg) q $+ GetMessageCfg+ { gmc_ackTimeout = minutes 1+ , gmc_messages = 1+ , gmc_waitTime = seconds 10+ }+ case msgs of+ [] -> fetchLoop+ (x : _) -> pure x+ msg <- fetchLoop+ payload <- sc_readJob cfg (sm_payload msg)+ pure (sm_handle msg, payload)++confirm :: SqsConfig j -> AWSQueue -> MessageHandle -> IO ()+confirm cfg q handle =+ sqsAckMessage (sc_aws cfg) q handle++repProgress :: SqsConfig j -> AWSQueue -> MessageHandle -> IO ()+repProgress cfg q handle =+ sqsChangeMessageTimeout (sc_aws cfg) q handle (minutes 1)++rollback :: SqsConfig j -> AWSQueue -> MessageHandle -> IO ()+rollback _ _ _ = pure ()