Skip to content

feat: Modify the way of creating cronjob#8403

Merged
f2c-ci-robot[bot] merged 1 commit intodev-v2from
pr@dev-v2@feat_cronjob
Apr 16, 2025
Merged

feat: Modify the way of creating cronjob#8403
f2c-ci-robot[bot] merged 1 commit intodev-v2from
pr@dev-v2@feat_cronjob

Conversation

@ssongliu
Copy link
Copy Markdown
Member

No description provided.

@f2c-ci-robot
Copy link
Copy Markdown

f2c-ci-robot Bot commented Apr 16, 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.

}
export interface CronjobDelete {
ids: Array<number>;
cleanData: boolean;
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 several issues with this code:

  1. The addition of new fields (retryTimes, timeout, etc.) to both Item and CronjobCreate/CronjobOperate interfaces without updating corresponding types where these fields should be used can lead to compile errors when using the updated interfaces.

  2. The id field is duplicated in some interfaces (Cronjob, CronjobCreat, CronjobOperate). This inconsistency might cause confusion or bugs if not handled properly.

  3. Missing documentation or comments on the newly added fields can make it harder to understand their purpose and usage.

  4. There seems to be an indentation issue near "website" under SourceItems.

To resolve these issues:

  • Ensure all references to 'item.id' use the correct ID field from appropriate contexts.
  • Remove duplicate 'id' fields across different interfaces.
  • Add necessary comments above each new field explaining its purpose and functionality.
  • Correct the indentation around "website" under "SourceAccountItems".

Optimization suggestions could include checking whether sourceAccountIDs and downloadAccountID support more complex data structures and provide functions for easily manipulating them instead of relying solely on string representations. Additionally, considering adding error handling for null/undefined value checks before operations that rely on them would enhance robustness.

Comment thread agent/app/dto/cronjob.go

type CronjobUpdateStatus struct {
ID uint `json:"id" validate:"required"`
Status string `json:"status" validate:"required"`
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.

The changes include:

  1. Type Renaming: The struct CronjobCreate has been renamed to CronjobOperate. This is beneficial because it clearly indicates that this struct is used for operations rather than creating a new cron job.

  2. Addition of Missing Fields:

    • Added ID, which can be useful for identifying specific cron jobs when performing updates.
    • Added fields like Command, ContainerName, User, etc., based on the previous structs for clarity and completeness. These should be validated appropriately according to their types.
  3. Optimization Suggestions:

    • Consistency in Field Names: Ensure consistency between field names across all related structs (CronjobCreate, CronjobUpdate) if applicable, such as using common prefixes like App_, Website_, etc., instead of separate fields.
    • Validation Annotations: While validation annotations help maintain data integrity, ensure they do not conflict with each other or are overly restrictive (e.g., making fields required unnecessarily).
    • Comments: Add comments where necessary to explain complex logic or sections of code, especially important in areas involving script/custom execution paths.

Overall, these changes enhance readability and functionality while providing a clear structure for handling various operations related to cron jobs.

onOpenDialog(row.id + '');
},
},
{
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 several improvements and corrections in the provided code:

  1. Remove Unused Code: The OperateDialog component is unused and should be removed from the template.

  2. Consistent Use of Variables: Ensure consistent use of variable names throughout the script to avoid potential bugs or confusion.

  3. Routing Correction: The onOpenDialog function now navigates using Vue Router rather than creating an operation dialog directly.

  4. Code Formatting: Improve line spacing and consistency to enhance readability.

Here's the revised code with these changes:

<template>
    <div>
        <LayoutContent v-loading="loading" v-if="!isRecordShow" :title="$t('menu.cronjob')">
            <template #leftToolBar>
                <el-button type="primary" @click="onOpenDialog('create')">
                    {{ $t('commons.button.create') }}{{ $t('menu.cronjob') }}
                </el-button>
                <el-button-group class="ml-4">
                <!-- Other left toolbar elements -->
                </el-button-group>
            </template>
        </LayoutContent>

        <Records @search="search" ref="dialogRecordRef" />
        <Backups @search="search" ref="dialogBackupRef" />
    </div>
</template>

<script lang="ts" setup>
import Records from '@/views/cronjob/cronjob/record/index.vue';
import Backups from '@/views/cronjob/cronjob/backup/index.vue';
import { computed, onMounted, reactive, ref } from 'vue';
import { ElMessageBox } from 'element-plus';
import { MsgSuccess } from '@/utils/message';
import { transSpecToStr } from './helper';
import { GlobalStore } from '@/store';

const globalStore = GlobalStore();
const mobile = computed(() => {
  // Compute logic here if needed
});

const loading = ref(false);
const isRecordShow = ref(true); // Assuming this is set elsewhere

// Functionality for searching
const search = async (column?: any) => {
  // Handle search functionality
};

const dialogRecordRef = ref();
const dialogBackupRef = ref();

// New function for opening dialogs based on ID
const onOpenDialog = async (id: string) => {
  router.push({ name: 'CronjobOperate', query: { id: id } });
};

const onDelete = async (row: Cronjob.CronjobInfo | null) => {
  // Implement delete functionality
};

const buttons = [
  {
    label: i18n.global.t('commons.button.edit'),
    click: (row: Cronjob.CronjobInfo) => {
      onOpenDialog(row.id + '');
    },
  },
  {
    // Other button configurations
  },
];
</script>

These changes address the identified issues and improve maintainability and structure of the code.

@sonarqubecloud
Copy link
Copy Markdown

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 16, 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 merged commit d10d83b into dev-v2 Apr 16, 2025
6 checks passed
@f2c-ci-robot f2c-ci-robot Bot deleted the pr@dev-v2@feat_cronjob branch April 16, 2025 06:00
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