Documentation ¶
Overview ¶
Package filelocker provide an upload locker based on the local file system.
It provides an exclusive upload locking mechanism using lock files which are stored on disk. Each of them stores the PID of the process which acquired the lock. This allows locks to be automatically freed when a process is unable to release it on its own because the process is not alive anymore. For more information, consult the documentation for handler.LockerDataStore interface, which is implemented by FileLocker.
If somebody tries to acquire a lock that is already held, the `requestRelease` callback will be invoked that was provided when the lock was successfully acquired the first time. The lock holder should then cease its operation and release the lock properly, so somebody else can acquire it. Under the hood, this is implemented using an additional file. When an already held lock should be released, a `.stop` file is created on disk. The lock holder regularly checks if this file exists. If so, it will call its `requestRelease` function.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FileLocker ¶
type FileLocker struct { // Relative or absolute path to store files in. FileStore does not check // whether the path exists, use os.MkdirAll in this case on your own. Path string // HolderPollInterval specifies how often the holder of a lock should check // if it should release the lock. The check involves querying if a `.stop` // file exists on disk. Defaults to 1 second. HolderPollInterval time.Duration // AcquirerPollInterval specifies how often the acquirer of a lock should // check if the lock has already been released. The checks are stopped if // the context provided to Lock is cancelled. Defaults to 3 seconds. AcquirerPollInterval time.Duration }
See the handler.DataStore interface for documentation about the different methods.
func New ¶
func New(path string) FileLocker
New creates a new file based storage backend. The directory specified will be used as the only storage entry. This method does not check whether the path exists, use os.MkdirAll to ensure. In addition, a locking mechanism is provided.
func (FileLocker) UseIn ¶
func (locker FileLocker) UseIn(composer *handler.StoreComposer)
UseIn adds this locker to the passed composer.