2017-03-13 1 views
0

残念なことに、パッケージhgearmanはテストや例を提供せず、gearman job serverにジョブを入れるにはconnectGearmansubmitJobをどのように組み合わせるべきか自分では解決できません。hgearman-clientはどのように機能しますか?

connectGearmanの結果は次のとおりです。

ghci> conn <- connectGearman (B.pack "x") ("localhost"::HostName) (4730::Port) 
ghci> :t conn 
conn :: Either GearmanError GearmanClient 

しかしsubmitJobStateTを扱うプライベート関数submitを使用しています。だから私はconnectGearmanの結果がS.StateT GearmanClient IOに包まれるべきであると推測することができます。以下は

+0

私は[Haskellの初心者のメーリングリスト](https://mail.haskell.org/pipermail/beginners/2017-March/017435.htmlでいくつかの助けを得ました)。私はすぐに自分の質問に対する答えを提供します。 – palik

+0

[ここ](https://github.com/p-alik/hgearman-client/blob/upstream/demos/submit-job.hs)は送信ジョブの例です – palik

答えて

0

Gearmanクライアントの私の実装です:

{-# LANGUAGE DeriveDataTypeable #-} 
import Control.Exception (Exception, IOException, catch, throwIO) 
import qualified Data.ByteString.Char8 as B 
import Data.Typeable  (Typeable) 
import qualified Network.Gearman.Client as C 
import Network.Gearman.Internal (Function, GearmanClient, GearmanError, Port, withGearman) 
import Network.Socket (HostName) 

data ConnectException = ConnectException HostName Port IOException 
    deriving (Show, Typeable) 
instance Exception ConnectException 

main :: IO() 
main = do 
    c <- C.connectGearman (B.pack "client-id") host port `catch` \e -> throwIO (ConnectException host port e) 
    either (error . B.unpack) return c 
    >>= submitFooJob 
    >>= either(error . B.unpack) (putStrLn . B.unpack) 
    return() 
    where 
     host = "localhost"::HostName 
     port = 4730::Port 
     submitFooJob :: GearmanClient -> IO (Either GearmanError B.ByteString) 
     submitFooJob gc = withGearman gc $ C.submitJob (B.pack "foo"::Function) (B.pack "bar") 
関連する問題