dizda / CloudBackupBundle

Be able to backup your database(s) and upload it to the cloud (Dropbox, Amazon S3, GoogleDrive, etc.)
MIT License
196 stars 57 forks source link

Better events and exceptions #90

Open Nyholm opened 8 years ago

Nyholm commented 8 years ago

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).

(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:

I suggest we should create these exception classes and then make sure that our managers do not throw any other exceptions.

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

dizda commented 8 years ago

Looks great!

Just realized that we may need the filename of the backup in BackupEvent?

Nyholm commented 8 years ago

Hm, tell me more. Why should filename be in the BackupEvent?

dizda commented 8 years ago

When you got many projects you might want to know which backup has been completed

Nyholm commented 8 years ago

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.

jongotlin commented 8 years ago

What BackupEvent could have as a property is how long it took the operation to finish.

Nyholm commented 8 years ago

Is that interesting for all events?

jongotlin commented 8 years ago

Only for those that actually may take some time.

dizda commented 8 years ago

@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?

Nyholm commented 8 years ago

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.

dizda commented 8 years ago

Oh ok I get it. So you suggest to add an event listener on both events to get the filename from the BackupEvent?

Nyholm commented 8 years ago

Yeah, That was my suggestion but I'm reconsidering it now. Because we might do things too complicated for the users.

ZCJ commented 7 years ago

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.