Skip to content

feat: Support the retention of remote backup files when deleting sche…#8296

Merged
f2c-ci-robot[bot] merged 1 commit intodevfrom
pr@dev@fix_cronjob_remote
Apr 2, 2025
Merged

feat: Support the retention of remote backup files when deleting sche…#8296
f2c-ci-robot[bot] merged 1 commit intodevfrom
pr@dev@fix_cronjob_remote

Conversation

@ssongliu
Copy link
Copy Markdown
Member

@ssongliu ssongliu commented Apr 2, 2025

Refs #8236

@f2c-ci-robot
Copy link
Copy Markdown

f2c-ci-robot Bot commented Apr 2, 2025

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.

Details

Instructions 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;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  1. Reduce Redundancy in onClean Function: The function can be simplified by directly calling deleteVisible.value = true; instead of using an if-else block.

    const onClean = async () => {
        deleteVisible.value = true;
        // Remove redundant lines inside the else branch
    };
  2. 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 {
Copy link
Copy Markdown
Member

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:

  1. New Fields:

    • CleanRemoteData is added to both CronjobClean and CronjobBatchDelete. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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 {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  1. Parameter Passing Consistency: Ensure that all variables passed to u.CleanRecord have consistent types and expected values.

    if !req.CleanRemoteData {
        for key := range accountMap {
            if key != constant.Local {
                delete(accountMap, key)
            }
        }
    }
  2. Type Annotations: Add type annotations where necessary, especially when defining new data structures.

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

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Apr 2, 2025

Copy link
Copy Markdown
Member

@wanghe-fit2cloud wanghe-fit2cloud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@wanghe-fit2cloud
Copy link
Copy Markdown
Member

/approve

@f2c-ci-robot
Copy link
Copy Markdown

f2c-ci-robot Bot commented Apr 2, 2025

[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

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@f2c-ci-robot f2c-ci-robot Bot added the approved label Apr 2, 2025
@f2c-ci-robot f2c-ci-robot Bot merged commit 90be745 into dev Apr 2, 2025
6 checks passed
@f2c-ci-robot f2c-ci-robot Bot deleted the pr@dev@fix_cronjob_remote branch April 2, 2025 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants