CloudBackupBundle
CloudBackupBundle copied to clipboard
Better events and exceptions
This is a suggestion to which events we should dispatch and exceptions we should throw. Please work with me and give me feedback.
What events to we got?
An event describes a thing that has happened. The event should be broad casted and not modified (you cant modify a radio borad cast). Nor should priority matter.
So, looking at our bundle. What does it? What happens?
The only place we do stuff is in the Managers. We have 3 managers and one "manager manager" (BackupManager
).
-
DatabaseManager
steps throw eachDatabaseInterface
and dumps it. -
ProcessorManager
does 3 things. It copies folders, compresses files and removes backup files. -
ClientManager
steps throw eachClientInterface
and upload every file. -
BackupManager
handles Exceptions had initiate the next step in the process.
(We should extract the filesystem actions from the ProcessorManager
)
I suggest events accordingly:
Event object | Properties | Event names (draft) |
---|---|---|
DatabaseEvent |
name, path | DumpCompleted |
ProcessorEvent |
name, path | CompressFilesCompleted |
FilesystemEvent |
filename | FilesCopied, FilesRemoved |
UploadEvent |
name, filname[] | UploadCompleted |
BackupEvent |
timeToFinish | BackupCompleted |
BackupFailedEvent |
name, type, message, timeToFail | BackupFailed |
With these new events a user could easily:
- Verify that the upload is completed (UploadEvent)
- Copy in more files to the zip (FilesystemEvent)
- Calculate hashes for the compressed files ( ProcessorEvent)
- Notify other services that the backup has happened (BackupEvent)
- etc etc.
What exceptions might occur?
I suggest we should create these exception classes and then make sure that our managers do not throw any other exceptions.
-
DatabaseException
-
ProcessorException
-
FilesystemException
-
UploadException
All of the above should implement BackupException
.
Centralized logging.
With these events we could centralize the logging into an event listener. We could also make sure to catch and logg all exceptions from the BackupManager
Looks great!
Just realized that we may need the filename of the backup in BackupEvent
?
Hm, tell me more. Why should filename be in the BackupEvent?
When you got many projects you might want to know which backup has been completed
The UploadEvent is dispatched after a file it uploaded. It might be one or it might be 100 files on 4 clients.
We can not use filename in Backup event since we don't know how many files or if they still are named the same.
We could however use the output_file_prefix
or a variant of that... But... tell me more. Where are you looking when you "want to know which backup has been completed". In a centralized logger? Don't you see from which project the logging messages comes from? I don't quite understand.
What BackupEvent
could have as a property is how long it took the operation to finish.
Is that interesting for all events?
Only for those that actually may take some time.
@Nyholm Hmm as far as I know, we only upload one archive to many destinations, so we know what will be the filename of the backup, right?
The UploadEvent
is dispatched from the ClientManger
it will know of the filenames.
But do you think it is within the scope of the BackupEvent
to know all the filenames that was uploaded?
Or, maybe it makes sense to have an array of filenames in the BackupEvent
form a DX perspective. It is a lot easier that collect info from UploadEvent
and then take action as soon as BackupEvent
is dispatched.
Oh ok I get it. So you suggest to add an event listener on both events to get the filename from the BackupEvent?
Yeah, That was my suggestion but I'm reconsidering it now. Because we might do things too complicated for the users.
so how would you get now the backup file name that is created? I understand that there is only 1 event dispatched upon success and the event itself does not have any information.
if ($successful) { $this->eventDispatcher->dispatch(BackupEvent::BACKUP_COMPLETED, new BackupEvent()); }
The reason I need the file name is that I need to send an email to the admin to inform him that the backup file (XXX) has been created and uploaded to storage.