Quantcast

how does hgearman-client work?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

how does hgearman-client work?

info-2

Hi,
I repeat my unanswered question in hope to find here some help:

Unfortunately the package hgearman does not provide any test or example and I can't work it out for myself how should be combined connectGearman and submitJob to put a job to the gearman job server.

The result of connectGearman is:

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

but submitJob uses private function submit which deals with StateT. So I can only guess the result of connectGearman should be wrapped into S.StateT GearmanClient IO without faintest idea how to do that.


_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how does hgearman-client work?

David McBride
This library seems badly managed, but it does give you just enough to
work with, if you know how to use monad transformers.

someprocedure :: IO Bool
someprocedure = do
  res <- connectGearman somebs somehost someport
  case res of
    Left e -> undefined
    Right client -> do
      (res, _) <- flip runStateT client $ do
        res <- submitJob somefunc somebs
        case res of
          Left e -> undefined
          Right bs -> do
            -- do something with bs
            return True
      return res

If I were you I'd turn LambdaCase on to clean it up a bit, and do
something like this.

{-# LANGUAGE LambdaCase #-}

...

someprocedure :: IO Bool
someprocedure = do
  connectGearman somebs somehost someport >>= \case
    Left e -> return False
    Right client -> do
      flip evalStateT client $ do
        submitJob somefunc somebs >>= \case
          Left e -> return False
          Right bs -> do
            -- do something with bs
            return True

On Wed, Mar 15, 2017 at 4:18 PM,  <[hidden email]> wrote:

> Hi,
> I repeat my unanswered question in hope to find here some help:
>
> Unfortunately the package hgearman does not provide any test or example and
> I can't work it out for myself how should be combined connectGearman and
> submitJob to put a job to the gearman job server.
>
> The result of connectGearman is:
>
> ghci> conn <- connectGearman (B.pack "x") ("localhost"::HostName)
> (4730::Port)
> ghci> :t conn
> conn :: Either GearmanError GearmanClient
>
> but submitJob uses private function submit which deals with StateT. So I can
> only guess the result of connectGearman should be wrapped into S.StateT
> GearmanClient IO without faintest idea how to do that.
>
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how does hgearman-client work?

info-2
I'm really much obliged for your support, David.

> This library seems badly managed, but it does give you just enough to
> work with, if you know how to use monad transformers.

It seems so. I tried to get some help by author at first: https://github.com/jperson/hgearman-client/issues/1

That's a reason why I'm working on PR to add some tests to the package.

Cheers,
Alexei

> On 16 March 2017 at 13:25 David McBride <[hidden email]> wrote:
>
>
> This library seems badly managed, but it does give you just enough to
> work with, if you know how to use monad transformers.
>
> someprocedure :: IO Bool
> someprocedure = do
>   res <- connectGearman somebs somehost someport
>   case res of
>     Left e -> undefined
>     Right client -> do
>       (res, _) <- flip runStateT client $ do
>         res <- submitJob somefunc somebs
>         case res of
>           Left e -> undefined
>           Right bs -> do
>             -- do something with bs
>             return True
>       return res
>
> If I were you I'd turn LambdaCase on to clean it up a bit, and do
> something like this.
>
> {-# LANGUAGE LambdaCase #-}
>
> ...
>
> someprocedure :: IO Bool
> someprocedure = do
>   connectGearman somebs somehost someport >>= \case
>     Left e -> return False
>     Right client -> do
>       flip evalStateT client $ do
>         submitJob somefunc somebs >>= \case
>           Left e -> return False
>           Right bs -> do
>             -- do something with bs
>             return True
>
> On Wed, Mar 15, 2017 at 4:18 PM,  <[hidden email]> wrote:
> > Hi,
> > I repeat my unanswered question in hope to find here some help:
> >
> > Unfortunately the package hgearman does not provide any test or example and
> > I can't work it out for myself how should be combined connectGearman and
> > submitJob to put a job to the gearman job server.
> >
> > The result of connectGearman is:
> >
> > ghci> conn <- connectGearman (B.pack "x") ("localhost"::HostName)
> > (4730::Port)
> > ghci> :t conn
> > conn :: Either GearmanError GearmanClient
> >
> > but submitJob uses private function submit which deals with StateT. So I can
> > only guess the result of connectGearman should be wrapped into S.StateT
> > GearmanClient IO without faintest idea how to do that.
> >
> >
> > _______________________________________________
> > Beginners mailing list
> > [hidden email]
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> >
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Loading...