Comments (6)
Hi,
For what purpose you need it? Probably to save state and continue execution later.
I have to create a basic save-stop-recovery-continue execution functionality.
The structure is:
Log (recovery mode or not) (pointer to the remaining elements not read) (all elements in reverse order)
Really only is necessary to persist the last element since it has all the log (reversed)
to save the state:
saveAndStop file= do
Log recovery _ log <- getData
if recovery then return () else do
writeFile file log
empty
loadAndRestart file proc= do
log <- readFile file
setData True (reverse log) log
proc
main= keep $ loadAndRestart "file" $ do
logged dothis
logged dothat
saveAndStop "file"
logged doOther
....
May execute, stop and continue if re-executed.
But I have to test it. the problem is that since TransIO can execute many threads, saveAndStop my write the log many times, one for each thread. Tomorrow I will try to make it work.
from transient.
Hi Alberto,
Thankyou for the speed response.
Yes to stop and continue execution later. Basically suspend and resume.
No hurry though. I am just playing around.
I would have thought that when we have
f = do
logged f1
logged f2
logged f3
suspend
later steps
That there would be three entries in the log, and that we need all three, as I will be running f again and each logged statement will read one of the log entries each?
Rene.
from transient.
Yes the file will have three entries.
In a general suspend
primitive for the TransIO monad, the file may have different many logs. For example :
f = do
logged $ f1
r <- logged $ choose [1.. 100]
logged $ print r
suspend
later steps
then the file will have 100 logs!!! of three elements each. but the first element is common to all the 100 logs. Since logs are generally very short, repetitions may not be a big problem in principle.
The logs are short since logged
erases the log steps that are inside. For example if f1
has dozens of log steps inside, it does not matter, there will be three entries in each log when suspend
is executed.
Then the restart would need to re-execute the 100 logs in 100 threads.
from transient.
Hi Rene:
I solved the single threaded case that may be useful for you:
suspend
, checkpoint
and restore
defined here, with an example:
{-# LANGUAGE ScopedTypeVariables #-}
import Transient.Base
import Control.Applicative
import Control.Monad.IO.Class
import Transient.Internals
import Transient.Logged
import Control.Exception
suspend :: String -> a -> TransIO a
suspend file x = do
Log recovery _ log <- getData `onNothing` return (Log False [] [])
if recovery then return x else do
liftIO $ writeFile file $ show log
exit x
checkpoint :: String -> TransIO ()
checkpoint file = do
Log recovery _ log <- getData `onNothing` return (Log False [] [])
if recovery then return () else do
liftIO $ writeFile file $ show log
return ()
restore :: String -> TransIO a -> TransIO a
restore file proc = do
log <- liftIO $ (readFile file >>= return . read) `catch` (\(e ::SomeException) -> return [])
setData $ Log True (reverse log) log
proc
main = keep $ restore "file" $ do
logged $ liftIO $ print "hello"
suspend "file" ()
logged $ liftIO $ print "world"
from transient.
Thankyou!
from transient.
Added restore, suspend and checkpoint for the general case:
If you can test that it works for you, it would be wonderful
from transient.
Related Issues (20)
- Collect and group have inconsistent behavior in failure case HOT 2
- Issues with the logging API HOT 2
- threads primitive does not work as expected with logging HOT 2
- Unify exceptions and finalization primitives HOT 1
- Lost or silently ignored exceptions HOT 5
- Cannot use an untyped expression (e.g. error and throw) as the last expression HOT 1
- Inconsistent exception behavior HOT 6
- Use raw fork instead of forkIO HOT 1
- build failure: TypeRep not in scope HOT 3
- grouByTime not working as expecred HOT 2
- cabal file: stated homepage does not exist HOT 1
- Strange hang with applicative code HOT 2
- Different underlying transport HOT 4
- when a exception handler does not match with the exception type, the exception stop backtracking
- Fails to build with GHC 8.6.4 HOT 4
- callService shouldn't need a previous established connection to call services HOT 1
- Undesired parallelism HOT 2
- `threads` management under exception handlers HOT 3
- Network.BSD.getProtocolByName: does not exist (no such protocol name: tcp)
- Build failure with mtl-2.3 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from transient.