mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-15 18:12:47 +03:00
Move lockfile logic into it's own file.
This commit is contained in:
parent
721945d1ba
commit
26f5964ef7
@ -105,6 +105,7 @@ import System.Environment (getProgName)
|
||||
import System.Posix.Signals (Handler(Catch), installHandler, sigTERM)
|
||||
import Text.Show.Pretty (pPrint)
|
||||
import Urbit.Time (Wen)
|
||||
import Vere.LockFile (lockFile)
|
||||
|
||||
import qualified CLI
|
||||
import qualified Data.Set as Set
|
||||
@ -196,21 +197,6 @@ tryPlayShip shipPath = do
|
||||
rio $ logTrace "SHIP RESUMED"
|
||||
Pier.pier shipPath Nothing sls
|
||||
|
||||
lockFile :: HasLogFunc e => FilePath -> RAcquire e ()
|
||||
lockFile pax = void $ mkRAcquire start stop
|
||||
where
|
||||
fil = pax <> "/.vere.lock"
|
||||
|
||||
stop handle = do
|
||||
logInfo $ display @Text $ ("Releasing lock file: " <> pack fil)
|
||||
io $ Lock.unlock fil handle
|
||||
|
||||
params = def { Lock.retryToAcquireLock = Lock.No }
|
||||
|
||||
start = do
|
||||
logInfo $ display @Text $ ("Taking lock file: " <> pack fil)
|
||||
io (Lock.lock params fil)
|
||||
|
||||
tryResume :: HasLogFunc e => FilePath -> RIO e ()
|
||||
tryResume shipPath = do
|
||||
rwith resumedPier $ \(serf, log, ss) -> do
|
||||
|
24
pkg/king/lib/Vere/LockFile.hs
Normal file
24
pkg/king/lib/Vere/LockFile.hs
Normal file
@ -0,0 +1,24 @@
|
||||
module Vere.LockFile (lockFile) where
|
||||
|
||||
import UrbitPrelude
|
||||
|
||||
import Data.Default (def)
|
||||
import System.IO.LockFile.Internal (LockingParameters(..), RetryStrategy(..),
|
||||
lock, unlock)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
lockFile :: HasLogFunc e => FilePath -> RAcquire e ()
|
||||
lockFile pax = void $ mkRAcquire start stop
|
||||
where
|
||||
fil = pax <> "/.vere.lock"
|
||||
|
||||
stop handle = do
|
||||
logInfo $ display @Text $ ("Releasing lock file: " <> pack fil)
|
||||
io $ unlock fil handle
|
||||
|
||||
params = def { retryToAcquireLock = No }
|
||||
|
||||
start = do
|
||||
logInfo $ display @Text $ ("Taking lock file: " <> pack fil)
|
||||
io (lock params fil)
|
Loading…
Reference in New Issue
Block a user