feat: Support the retention of remote backup files when deleting sche…#8296
feat: Support the retention of remote backup files when deleting sche…#8296f2c-ci-robot[bot] merged 1 commit intodevfrom
Conversation
|
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
|
|
||
| onBeforeUnmount(() => { | ||
| clearInterval(Number(timer)); | ||
| timer = null; |
There was a problem hiding this comment.
There are no major issues with the provided TypeScript code for this context. However, here are some minor optimization suggestions:
-
Reduce Redundancy in
onCleanFunction: The function can be simplified by directly callingdeleteVisible.value = true;instead of using anif-elseblock.const onClean = async () => { deleteVisible.value = true; // Remove redundant lines inside the else branch };
-
Inline Simple Conditions: If you frequently need to check if something is backup-related without reusing it elsewhere, consider inline checking inside functions that use this condition.
const cleanRecord = async () => { if (!isBackup()) { const delLoading value = true; await cleanRecords(dialogData.value.rowData.id, cleanData.value, cleanRemoteData.value) .then(() => { delLoading.value = false; deleteVisible.value = false; MsgSuccess(i18n.global.t('commons.msg.operationSuccess')); }) .catch(() => { delLoading.value = false; }); } else { // Handle other cases differently if needed } }; interface ResourceInterface { type: string | number; id: string | number; } function isBackup(item: ResourceInterface): boolean { return ['app', 'website', 'database', 'directory', 'snapshot', 'log'].includes( item.type.toLowerCase() ); }
These optimizations enhance readability and maintainability while preserving functionality.
| IDs []uint `json:"ids" validate:"required"` | ||
| } | ||
|
|
||
| type CronjobInfo struct { |
There was a problem hiding this comment.
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:
- The names of the fields are clear and descriptive. However, it would be beneficial if consistent naming conventions were used throughout all structs (e.g., starting properties with a lowercase letter) to maintain consistency across types.
-
Validation Tags:
- The 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.
- The validation tags (
-
Struct Usage:
- These structs appear to be part of a job scheduling system for downloading, cleaning, and potentially deleting data related to jobs. Consider adding comments explaining their purpose and usage within larger context descriptions.
-
Documentation:
- Since these structs are likely shared between different parts of an API or application layer, consider adding documentation on what each field represents and how they relate to the overall functionality.
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.
| 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 { |
There was a problem hiding this comment.
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:
-
Parameter Passing Consistency: Ensure that all variables passed to
u.CleanRecordhave consistent types and expected values.if !req.CleanRemoteData { for key := range accountMap { if key != constant.Local { delete(accountMap, key) } } }
-
Type Annotations: Add type annotations where necessary, especially when defining new data structures.
-
Logging Statements: Consider adding more detailed logging statements or using structured logs for better readability.
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.
|
|
/approve |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: wanghe-fit2cloud The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |



Refs #8236