Is it possible to use persistent inside a Process?

25 views
Skip to first unread message

Mike Chiao

unread,
May 13, 2013, 6:31:18 AM5/13/13
to parallel...@googlegroups.com
I'm currently trying to embed Cloud Haskell with Yesod framework.  I currently want to store data into database when a Process gets data from the cloud.  The backend I'm using is P2P and I'm using the following code:

-- To start the peer
bootstrap "127.0.0.1" "9001" "127.0.0.1:9002" mainProcess

mainProcess :: Process ()
mainProcess = do
        forever $ do
        liftIO $ threadDelay (2*1000000)
        nodeIds <- P2P.getPeers
        -- yesod persistent syntex
        _ <- runDB $ insert $ Peers (T.pack (show nodeIds))
        return ()

So whats the best way to run a database query inside a Process?  Do I need to make an instance for insert?


Tim Watson

unread,
May 13, 2013, 7:02:42 AM5/13/13
to coo...@gmail.com, parallel...@googlegroups.com
On 13 May 2013, at 11:31, Mike Chiao wrote:

I'm currently trying to embed Cloud Haskell with Yesod framework.  I currently want to store data into database when a Process gets data from the cloud.  The backend I'm using is P2P and I'm using the following code:

[snip]

So whats the best way to run a database query inside a Process?  Do I need to make an instance for insert?

Hi Mike,

I think the issue you're running into here is that Process needs to be changed to provide a MonadTrans instance (or similar) so that you can `lift' things other than IO into the Process. There is a ticket open for this at https://cloud-haskell.atlassian.net/browse/DP-70 - that's unlikely to make it into the forthcoming 0.5.0 release though, as I'm up to my eyeballs with other CH bugs/features, so if you want this badly then *please do* submit a pull request and I'll do the QA and integrate it into that release. Otherwise you'll probably have to wait for 0.6.0, unless I win the european lottery tomorrow night, in which case I'll quit my job and you can have that feature in 0.5.0 instead. ;)

If you need a workaround in the meanwhile, you could start the yesod handler and `liftIO $ forkProcess $ do ...' inside yesod's monad instead, but I realise that's hardly ideal.

Cheers,
Tim

Mike Chiao

unread,
May 14, 2013, 1:30:14 AM5/14/13
to parallel...@googlegroups.com, coo...@gmail.com
Dear Tim,

Thanks for the quick response!  In the end I used MVar to pass information between threads.  It's a work around but it's good enough for what I'm doing right now I think, not really finished so it may bring me problems later on.......

Regards,
Mike
Reply all
Reply to author
Forward
0 new messages