Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ServerLockExistsError ¶
type ServerLockExistsError struct {
// contains filtered or unexported fields
}
func (*ServerLockExistsError) Error ¶
func (e *ServerLockExistsError) Error() string
type ServerLockService ¶
ServerLockService allows servers in HA mode to claim a lock and execute a function if the server was granted the lock It exposes 2 services LockAndExecute and LockExecuteAndRelease, which are intended to be used independently, don't mix them up (ie, use the same actionName for both of them).
func ProvideService ¶
func ProvideService(sqlStore db.DB, tracer tracing.Tracer) *ServerLockService
func (*ServerLockService) LockAndExecute ¶
func (sl *ServerLockService) LockAndExecute(ctx context.Context, actionName string, maxInterval time.Duration, fn func(ctx context.Context)) error
LockAndExecute try to create a lock for this server and only executes the `fn` function when successful. This should not be used at low internal. But services that needs to be run once every ex 10m.
func (*ServerLockService) LockExecuteAndRelease ¶
func (sl *ServerLockService) LockExecuteAndRelease(ctx context.Context, actionName string, maxInterval time.Duration, fn func(ctx context.Context)) error
LockExecuteAndRelease Creates the lock, executes the func, and then release the locks. The locking mechanism is based on the UNIQUE constraint of the actionName in the database (column operation_uid), so a new process can not insert a new operation if already exists one. The parameter 'maxInterval' is a timeout safeguard, if the LastExecution in the database is older than maxInterval, we will assume the lock as timeouted. The 'maxInterval' parameter should be so long that is impossible for 2 processes to run at the same time.