async def workspace_create(self, name: EntryName) -> EntryID: assert isinstance(name, EntryName) async with self._update_user_manifest_lock: timestamp = self.device.timestamp() workspace_entry = WorkspaceEntry.new(name, timestamp=timestamp) user_manifest = self.get_user_manifest() user_manifest = user_manifest.evolve_workspaces_and_mark_updated( timestamp, workspace_entry) # Given *we* are the creator of the workspace, our placeholder is # the only non-speculative one. # # Note the save order is important given there is no atomicity # between saving the non-speculative workspace manifest placeholder # and the save of the user manifest containing the workspace entry. # Indeed, if we would save the user manifest first and a crash # occured before saving the placeholder, we would endup in the same # situation as if the workspace has been created by someone else # (i.e. a workspace entry but no local data about this workspace) # so we would fallback to a local speculative workspace manifest. # However a speculative manifest means the workspace have been # created by somebody else, and hence we shouldn't try to create # it corresponding realm in the backend ! await workspace_storage_non_speculative_init( data_base_dir=self.data_base_dir, device=self.device, workspace_id=workspace_entry.id, ) await self.set_user_manifest(user_manifest) self.event_bus.send(CoreEvent.FS_ENTRY_UPDATED, id=self.user_manifest_id) self.event_bus.send(CoreEvent.FS_WORKSPACE_CREATED, new_entry=workspace_entry) return workspace_entry.id
async def _transactions_factory(device, backend_cmds, local_storage, cls=SyncTransactions): def _get_workspace_entry(): return workspace_entry workspace_entry = WorkspaceEntry.new("test") workspace_manifest = LocalWorkspaceManifest.new_placeholder( id=workspace_entry.id, now=Pendulum(2000, 1, 1) ) async with local_storage.lock_entry_id(workspace_entry.id): await local_storage.set_manifest(workspace_entry.id, workspace_manifest) remote_devices_manager = remote_devices_manager_factory(device) remote_loader = RemoteLoader( device, workspace_entry.id, _get_workspace_entry, backend_cmds, remote_devices_manager, local_storage, ) return cls( workspace_entry.id, _get_workspace_entry, device, local_storage, remote_loader, event_bus, )
async def workspace_create(self, name: AnyEntryName) -> EntryID: """ Raises: Nothing ! """ name = EntryName(name) workspace_entry = WorkspaceEntry.new(name) workspace_manifest = LocalWorkspaceManifest.new_placeholder(id=workspace_entry.id) async with self._update_user_manifest_lock: user_manifest = self.get_user_manifest() user_manifest = user_manifest.evolve_workspaces_and_mark_updated(workspace_entry) await self._create_workspace(workspace_entry.id, workspace_manifest) await self.set_user_manifest(user_manifest) self.event_bus.send("fs.entry.updated", id=self.user_manifest_id) self.event_bus.send("fs.workspace.created", new_entry=workspace_entry) return workspace_entry.id
async def workspace_create(self, name: AnyEntryName) -> EntryID: """ Raises: Nothing ! """ name = EntryName(name) workspace_entry = WorkspaceEntry.new(name) workspace_manifest = LocalWorkspaceManifest.new_placeholder( self.device.device_id, id=workspace_entry.id ) async with self._update_user_manifest_lock: user_manifest = self.get_user_manifest() user_manifest = user_manifest.evolve_workspaces_and_mark_updated(workspace_entry) await self._create_workspace(workspace_entry.id, workspace_manifest) await self.set_user_manifest(user_manifest) self.event_bus.send(CoreEvent.FS_ENTRY_UPDATED, id=self.user_manifest_id) self.event_bus.send(CoreEvent.FS_WORKSPACE_CREATED, new_entry=workspace_entry) return workspace_entry.id
async def _transactions_factory(device, local_storage, cls=SyncTransactions): def _get_workspace_entry(): return workspace_entry async def _get_previous_workspace_entry(): # The tests shouldn't need this yet assert False workspace_entry = WorkspaceEntry.new(EntryName("test"), device.timestamp()) workspace_manifest = LocalWorkspaceManifest.new_placeholder( device.device_id, id=workspace_entry.id, timestamp=datetime(2000, 1, 1)) async with local_storage.lock_entry_id(workspace_entry.id): await local_storage.set_manifest(workspace_entry.id, workspace_manifest) async with backend_authenticated_cmds_factory( device.organization_addr, device.device_id, device.signing_key) as cmds: remote_devices_manager = remote_devices_manager_factory(device) remote_loader = RemoteLoader( device, workspace_entry.id, _get_workspace_entry, _get_previous_workspace_entry, cmds, remote_devices_manager, local_storage, ) yield cls( workspace_entry.id, _get_workspace_entry, device, local_storage, remote_loader, event_bus, core_config, )
async def _transactions_factory(device, backend_cmds, local_storage, cls=SyncTransactions): def _get_workspace_entry(): return workspace_entry async def _get_previous_workspace_entry(): # The tests shouldn't need this yet assert False workspace_entry = WorkspaceEntry.new("test") workspace_manifest = LocalWorkspaceManifest.new_placeholder( device.device_id, id=workspace_entry.id, now=datetime(2000, 1, 1)) async with local_storage.lock_entry_id(workspace_entry.id): await local_storage.set_manifest(workspace_entry.id, workspace_manifest) remote_devices_manager = remote_devices_manager_factory(device) remote_loader = RemoteLoader( device, workspace_entry.id, _get_workspace_entry, _get_previous_workspace_entry, backend_cmds, remote_devices_manager, local_storage, ) return cls( workspace_entry.id, _get_workspace_entry, device, local_storage, remote_loader, event_bus, )