-
Couldn't load subscription status.
- Fork 0
Data Worker
The data worker is responsible for managing the operations of storing, retrieving and deleting data records.
Several methods are needed from a data worker; these are defined on the data worker interface (IDataWorker). We will now take a look at each method and discuss what the intent of the method is.
The write method is intened to stage data ready to be commited to the data storage system. For example if storing data in a file the write method would write the message pack serialized data to the file stream but would not close the stream. The write method is not intended to commit data to the store as there are some operations that might happen after write that means the data write should be discarded. The write method should allow for data to be create new and update existing data if it exists.
Task<bool> Write<TDataType>(int id, TDataType data) where TDataType : DataEntity;The Id is the id that the data manager has provided for the data in the default data worker this will be the Id property from the data object but other data managers may not use this as the Id when calling the write method.
The commit method is intened to commit the staged data that has been propered by a write method call for the specific data id.
Task<bool> Commit<TDataType>(int id) where TDataType : DataEntity;In the case of the file write example from the write method the commit method would close the file stream to flush the staged data onto the disk.
The data manager may decided that both a write and a commit should happen at once to handle this the data worker has a method for preforming this operation. When creating your own data worker it is advicable to have this method use the write method and commit methods from above and to handle the case of an operatio failing gracefully.
Task<bool> WriteAndCommit<TDataType>(int id, TDataType data) where TDataType : DataEntity;As you can see the write and commit method takes in both the id and the data to be written.
The data manager may decide that the data that has been staged is not to be written due to another part of a write process failing. This method should dispose of any data pending a commit so that it will never be commited.
Task DiscardChanges<TDataType>(int id) where TDataType : DataEntity;The id is the id of the data that was requested to be stage.
This method is used to undo any changes to data that have been commited. The rollback method should override any data stored on the id provided with the data provided, this mean that the method should act like write and commit but the is intended to never fail it should always keep trying to persist the data until it can.
Task Rollback<TDataType>(int id, TDataType data) where TDataType : DataEntity;