Skip to content

Conversation

@shaohuzhang1
Copy link
Contributor

… displayed incorrectly

What this PR does / why we need it?

Summary of your change

Please indicate you've done the following:

  • Made sure tests are passing and test coverage is added if needed.
  • Made sure commit message follow the rule of Conventional Commits specification.
  • Considered the docs impact and opened a new docs issue or PR with docs changes if needed.

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Dec 10, 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-sigs/prow repository.

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Dec 10, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:

The full list of commands accepted by this bot can be found 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

node.context['run_time'] = time.time() - node.context.get("start_time")


def get_write_context(loop_type, array, number, loop_body):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The provided code snippet appears to be part of a workflow management function that is handling nested loops and iterating through an array. Here are some points to consider:

  1. Variable Naming: The variable node seems to represent an instance of an interface (INode). It would be beneficial to add more meaningful names to variables like current_index, loop_answer_data, and array.

  2. Index Initialization: Ensure that current_index starts at 0 before entering the loop.

  3. Time Measurement: The calculation of run_time should only occur after all iterations have been completed, otherwise, it will always show the elapsed time since the start of the node execution rather than just the runtime for each iteration.

  4. Loop Iteration: If you expect multiple passes over the same data, ensure that number represents the number of times you want to iterate over the entire array. Otherwise, if you pass in number=1, it might lead to unexpected behavior depending on the context.

Here's a revised version of the function with these considerations:

def loop(workflow_manage_new_instance, node: INode, generate_loop):
    # Initialize necessary contexts
    current_index = 0
    loop_answer_data = []
    index_key = "index"
    item_key = "item"

    # Calculate start time once before entering the loop
    start_time = time.time()

    # Main loop
    while current_index < len(array):
        # Process data using current item
        currentItem = array[current_index]
        
        # Generate output for current iteration
        loop_output = generate_loop(currentItem)
        loop_answer_data.append(loop_output)

        # Update indices
        node.context[index_key] = current_index
        node.context[item_key] = currentItem

        # Increment current index
        current_index += 1

    # Calculate total run time after all iterations
    node.context['run_time'] = time.time() - start_time

def get_write_context(loop_type, array, number, loop_body):
    # Implement logic to write context based on loop type
    pass

Key Changes:

  • Added comments for clarity.
  • Initialized current_index to 0 before the loop.
  • Moved time measurement outside of the loop to calculate the total time taken for processing the array.
  • Ensured consistent naming conventions (e.g., renaming item to current_item) throughout the function.

@shaohuzhang1 shaohuzhang1 merged commit 9fc1809 into v2 Dec 10, 2025
3 of 6 checks passed
@shaohuzhang1 shaohuzhang1 deleted the pr@v2@fix_workflow branch December 10, 2025 03:01
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.

2 participants