Skip to content

Add hook so that after each action a process can be started#6

Merged
neonima merged 1 commit intomainfrom
add-hook
May 11, 2025
Merged

Add hook so that after each action a process can be started#6
neonima merged 1 commit intomainfrom
add-hook

Conversation

@neonima
Copy link
Owner

@neonima neonima commented May 11, 2025

Add Post-Action Hook Support

Summary

This PR adds functionality to execute a hook/callback after each action in the Runner. This enhancement allows for post-action processing, enabling better control and monitoring of action execution.

Changes

  • Added post-action hook execution functionality to the Runner
  • Implemented option for configuring post-action behavior WithHook
  • Added test coverage demonstrating hook functionality

Details

The implementation allows hooks to be registered during Runner creation that will execute after each action completion. The hooks receive the context and can return an error to affect execution flow.

Key Features

  • Hook execution after each action
  • Error propagation from hooks
  • Context passing to hooks for proper cancellation support
  • Chainable configuration through options pattern

Test Coverage

Added comprehensive tests that verify:

  • Basic hook execution
  • Error propagation from hooks
  • Context cancellation handling
  • State maintenance during hook execution

Example Usage

runner := action.New(action.WithHook(func(ctx context.Context) error {
    // Post-action processing here
    return nil
}))

Testing

All tests pass, including new test cases covering hook functionality:

  • Successful hook execution validation
  • Error propagation scenarios
  • State verification before and after hook execution

@neonima neonima requested a review from Copilot May 11, 2025 08:07
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces post-action hook functionality to the Runner, allowing additional processing steps after each action execution. Key changes include adding hook support via the WithHook option, updating the Runner’s error and done channel handling, and extending test coverage to verify hook behavior and error propagation.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
runner.go Integrated hook execution logic and refactored error handling using atomic pointers and done channel.
runner_test.go Added tests to verify runner shutdown, error propagation, and hook functionality.
Comments suppressed due to low confidence (1)

runner_test.go:57

  • In TestRunner_Error, the test cancels the context but does not wait for the runner to finish (e.g. by reading from Done()) or assert the error via r.Error(). Consider waiting for the runner to complete and then asserting the error to verify proper error propagation.
cancel()

@neonima neonima merged commit 02f702b into main May 11, 2025
1 check passed
@neonima neonima deleted the add-hook branch May 11, 2025 08:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant