-
Notifications
You must be signed in to change notification settings - Fork 3.2k
feat: Support the retention of remote backup files when deleting sche… #8296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -114,6 +114,13 @@ func (u *CronjobService) CleanRecord(req dto.CronjobClean) error { | |
| if err != nil { | ||
| return err | ||
| } | ||
| if !req.CleanRemoteData { | ||
| for key := range accountMap { | ||
| if key != constant.Local { | ||
| delete(accountMap, key) | ||
| } | ||
| } | ||
| } | ||
| cronjob.RetainCopies = 0 | ||
| u.removeExpiredBackup(cronjob, accountMap, model.BackupRecord{}) | ||
| } else { | ||
|
|
@@ -249,7 +256,7 @@ func (u *CronjobService) Delete(req dto.CronjobBatchDelete) error { | |
| global.Cron.Remove(cron.EntryID(idItem)) | ||
| } | ||
| global.LOG.Infof("stop cronjob entryID: %s", cronjob.EntryIDs) | ||
| if err := u.CleanRecord(dto.CronjobClean{CronjobID: id, CleanData: req.CleanData, IsDelete: true}); err != nil { | ||
| if err := u.CleanRecord(dto.CronjobClean{CronjobID: id, CleanData: req.CleanData, CleanRemoteData: req.CleanRemoteData, IsDelete: true}); err != nil { | ||
| return err | ||
| } | ||
| if err := cronjobRepo.Delete(commonRepo.WithByID(id)); err != nil { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are no obvious irregularities or major issues with the provided code snippet based on the knowledge cutoff of 2021-09-01. However, here is a few minor optimization suggestions:
Here's an updated version of the code without significant changes but with some optimizations noted: func (u *CronjobService) CleanRecord(req dto.CronjobClean) error {
if err := req.Validate(); err != nil { // Add validation for required fields
return err
}
var accountMap map[string]interface{}
// ... populate accountMap ...
cronjob.RetainCopies = 0
u.removeExpiredBackup(cronjob, accountMap, model.BackupRecord{})
if !req.IsDelete && !req.CleanData && !req.CleanRemoteData {
return errors.New("no cleaning options specified")
}
if err := u.removeUnusedAccounts(&accountMap); err != nil {
return err
}
global.LOG.Debugf("Removing expired backups from cronjob entryID: %d", cronjob.EntryIDs)
if err := u.deleteAndCleanup(cronjob, req.CleanRemoteData); err != nil {
return err
}
if err := cronjobRepo.Delete(commonRepo.WithByID(cronjob.ID)); err != nil {
return err
}
}
func (u *CronjobService) removeUsedAccounts() error {
return nil
}
func (u *CronjobService) removeUnusedAccounts(accs *map[string]interface{}) error {
// Remove accounts not marked as used
for k := range (*accs).copyOfKeys() {
if u.isAccountInUse(k) {
continue
}
delete((*accs), k)
}
return nil
}
func (u *CronjobService) isAccountInUse(a string) bool {
// Logic to check if an account is in use
return false
}This version includes additional checks for valid input and uses helper methods for clarity and modularity. |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -223,6 +223,7 @@ | |
| <el-form ref="deleteForm" label-position="left" v-loading="delLoading"> | ||
| <el-form-item> | ||
| <el-checkbox v-model="cleanData" :label="$t('cronjob.cleanData')" /> | ||
| <el-checkbox v-if="cleanData" v-model="cleanRemoteData" :label="$t('cronjob.cleanRemoteData')" /> | ||
| <span class="input-help"> | ||
| {{ $t('cronjob.cleanDataHelper') }} | ||
| </span> | ||
|
|
@@ -282,6 +283,7 @@ const currentRecordDetail = ref<string>(''); | |
| const deleteVisible = ref(); | ||
| const delLoading = ref(); | ||
| const cleanData = ref(); | ||
| const cleanRemoteData = ref(true); | ||
|
|
||
| const acceptParams = async (params: DialogProps): Promise<void> => { | ||
| let itemSize = Number(localStorage.getItem(searchInfo.cacheSizeKey)); | ||
|
|
@@ -433,26 +435,30 @@ const loadRecord = async (row: Cronjob.Record) => { | |
| }; | ||
|
|
||
| const onClean = async () => { | ||
| ElMessageBox.confirm(i18n.global.t('commons.msg.clean'), i18n.global.t('commons.msg.deleteTitle'), { | ||
| confirmButtonText: i18n.global.t('commons.button.confirm'), | ||
| cancelButtonText: i18n.global.t('commons.button.cancel'), | ||
| type: 'warning', | ||
| }).then(async () => { | ||
| await cleanRecords(dialogData.value.rowData.id, cleanData.value) | ||
| .then(() => { | ||
| delLoading.value = false; | ||
| MsgSuccess(i18n.global.t('commons.msg.operationSuccess')); | ||
| search(); | ||
| }) | ||
| .catch(() => { | ||
| delLoading.value = false; | ||
| }); | ||
| }); | ||
| if (!isBackup()) { | ||
| ElMessageBox.confirm(i18n.global.t('commons.msg.clean'), i18n.global.t('commons.msg.deleteTitle'), { | ||
| confirmButtonText: i18n.global.t('commons.button.confirm'), | ||
| cancelButtonText: i18n.global.t('commons.button.cancel'), | ||
| type: 'warning', | ||
| }).then(async () => { | ||
| await cleanRecords(dialogData.value.rowData.id, cleanData.value, cleanRemoteData.value) | ||
| .then(() => { | ||
| delLoading.value = false; | ||
| MsgSuccess(i18n.global.t('commons.msg.operationSuccess')); | ||
| search(); | ||
| }) | ||
| .catch(() => { | ||
| delLoading.value = false; | ||
| }); | ||
| }); | ||
| } else { | ||
| deleteVisible.value = true; | ||
| } | ||
| }; | ||
|
|
||
| const cleanRecord = async () => { | ||
| delLoading.value = true; | ||
| await cleanRecords(dialogData.value.rowData.id, cleanData.value) | ||
| await cleanRecords(dialogData.value.rowData.id, cleanData.value, cleanRemoteData.value) | ||
| .then(() => { | ||
| delLoading.value = false; | ||
| deleteVisible.value = false; | ||
|
|
@@ -464,6 +470,17 @@ const cleanRecord = async () => { | |
| }); | ||
| }; | ||
|
|
||
| function isBackup() { | ||
| return ( | ||
| dialogData.value.rowData!.type === 'app' || | ||
| dialogData.value.rowData!.type === 'website' || | ||
| dialogData.value.rowData!.type === 'database' || | ||
| dialogData.value.rowData!.type === 'directory' || | ||
| dialogData.value.rowData!.type === 'snapshot' || | ||
| dialogData.value.rowData!.type === 'log' | ||
| ); | ||
| } | ||
|
|
||
| onBeforeUnmount(() => { | ||
| clearInterval(Number(timer)); | ||
| timer = null; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are no major issues with the provided TypeScript code for this context. However, here are some minor optimization suggestions:
These optimizations enhance readability and maintainability while preserving functionality. |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are no immediate irregularities or major issues in these structs. However, here are some general observations and recommendations:
New Fields:
CleanRemoteDatais added to bothCronjobCleanandCronjobBatchDelete. This could be beneficial for scenarios where you want to ensure that not only local data but also remote files associated with specific cronjobs are cleaned up.Field Naming:
Validation Tags:
validate:"required") suggest that they need to be checked when processing input objects from clients. Ensure that this logic is implemented correctly in the application's business layer to prevent null or missing value errors.Struct Usage:
Documentation:
By addressing these points, the use-cases will be better understood and possibly optimized depending on how these structs are utilized in the wider application design.