From 6024cfff98e5be56d829b490df442cd9265b0aa8 Mon Sep 17 00:00:00 2001 From: DanB Date: Thu, 6 Oct 2016 20:01:56 +0200 Subject: [PATCH] Remote locks implementation, fixes #525 --- apier/v1/apier.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/apier/v1/apier.go b/apier/v1/apier.go index 081e31155..9ba621e5f 100644 --- a/apier/v1/apier.go +++ b/apier/v1/apier.go @@ -24,6 +24,7 @@ import ( "path" "strconv" "strings" + "time" "github.com/cgrates/cgrates/cache2go" "github.com/cgrates/cgrates/config" @@ -1078,3 +1079,20 @@ func (self *ApierV1) RemoveActions(attr AttrRemoveActions, reply *string) error *reply = utils.OK return nil } + +type AttrRemoteLock struct { + LockIDs []string // List of IDs to obtain lock for + Timeout time.Duration // Automatically unlock on timeout +} + +func (self *ApierV1) RemoteLock(attr AttrRemoteLock, reply *string) error { + engine.Guardian.GuardIDs(attr.Timeout, attr.LockIDs...) + *reply = utils.OK + return nil +} + +func (self *ApierV1) RemoteUnlock(lockIDs []string, reply *string) error { + engine.Guardian.UnguardIDs(lockIDs...) + *reply = utils.OK + return nil +}