RemoteStateProvider
Implements
Index
Constructors
constructor
Parameters
options: { appId: string; localStateDirectoryPath: string; lockContext?: string; organizationId: string; sessionId: string; stateManagementServiceUrl: string }
organizationIdandappIdname the app whose state this is, andsessionIdis the session the run acts as.stateManagementServiceUrlis the backend service, including the prefix its routes sit behind.localStateDirectoryPathis the directory state files are written into.lockContextis what a blocked run is shown about the holder.appId: string
localStateDirectoryPath: string
optionallockContext: string
organizationId: string
sessionId: string
stateManagementServiceUrl: string
Returns RemoteStateProvider
Methods
getAppLock
The id of the lock currently held, or
undefinedwhen the app is unlocked.Returns Promise<string | undefined>
getSealedStates
Reads state files from the newest sealed state, bringing the directory up to it first, and holding the upload lock throughout so that nothing replaces the directory between the reads.
Parameters
stateFileNames: string[]
Returns Promise<(Buffer<ArrayBufferLike> | undefined)[]>
getState
Reads a state file.
Parameters
stateFileName: string
Returns Promise<Buffer<ArrayBufferLike>>
getTemporaryFilePath
A new path beside the state files. See LocalStateProvider.getTemporaryFilePath.
Parameters
name: string
Returns Promise<string>
isAppLocked
Whether
lockIdis the lock currently held.Parameters
lockId: string
Returns Promise<boolean>
listStates
The names of the state files whose name starts with
prefix.Parameters
prefix: string
Returns Promise<string[]>
lockApp
Takes the app lock and opens the run's record with everything the state directory holds.
With
lockId, resumes the run already holding that lock instead - from any machine, as the account that took it or an organization administrator. The state directory is replaced with what that run wrote so far, its journal included, keeping this machine's journal files, which join the record, and every write after lands in its record. A run that wrote nothing is resumed from the newest sealed state, without that state's journal.Parameters
lock: { commitId: string } | { lockId: string }
commitId: string
lockId: string
Returns Promise<{ commitId?: string; lockId: string; resumedFrom?: directory | run | sealed }>
refreshState
Brings the state directory up to the newest sealed state, which is what a run plans against.
A directory an open run is still writing is left alone. A directory the backend holds nothing for is left alone too: that is a first run, or a project arriving from another provider, and the files on disk are the only copy there is. Journal files are neither replaced nor taken.
Returns Promise<{ commitId?: string; previousCommitId?: string; replaced: boolean }>
saveStates
Writes state files, deleting each one given no
data, and then writes the run's record once for all of them when a run is open.Parameters
stateFiles: ({ data: Buffer<ArrayBufferLike> | undefined; stateFileName: string } | { filePath: string; stateFileName: string })[]
Returns Promise<void>
unlockApp
Writes the directory into the run's record, seals it, and releases the app lock, then archives the directory with LocalStateProvider.archiveState when it holds that run. Unlocking an app that is not locked is not an error.
A write that failed earlier left the directory ahead of the record, so the record is written once more before it is sealed: a sealed record is what every machine plans against next. The archive is this machine's history, so a failure to write it is reported on stderr rather than thrown.
Parameters
lockId: string
Returns Promise<void>
Keeps state in Octo's managed backend, so a team shares one store and no machine holds the only copy.
A run reads and writes a state directory on disk through LocalStateProvider, which archives each run there when its lock is released, and the backend is kept in step with it:
octo generateplans against.Two files of the provider's own sit beside the state files and are never uploaded:
remote-state.lockrecords the run the directory belongs to and is deleted when the lock is released, andremote-state-upload.lockmakes the octo processes of one machine write to the backend one at a time and is deleted after every write.Services/State Management
Techniques for State Providers.