Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for handling success and failure cases in target ex… #158

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Notchayan
Copy link

Pull Request description

This PR adds support for success and failure handlers in tasks, allowing execution of specific commands based on the task's outcome. This enables better control flow and error handling in Makim tasks.

Features added:

  • Success handlers: Execute commands when tasks complete successfully
  • Failure handlers: Execute commands when tasks fail
  • Remote execution support for both handlers
  • File-based verification for handler execution
  • Proper cleanup after handler execution

Resolves #18

How to test these changes

Test local handlers:

# Test success handler
makim tests.success-test
cat /tmp/makim-handler-test  # Should show "SUCCESS"

# Test failure handler
makim tests.failure-test
cat /tmp/makim-handler-test  # Should show "FAILURE"

Test remote handlers:

# Start SSH test container
makim docker.start

# Test remote success handler
makim tests.success-remote
cat /tmp/makim-remote-test  # Should show "REMOTE_SUCCESS"

# Test remote failure handler
makim tests.failure-remote
cat /tmp/makim-remote-test  # Should show "REMOTE_FAILURE"

Run all handler tests:

makim tests.unittest

Pull Request checklists

This PR is a:

  • new feature: Adds success/failure handlers

About this PR:

  • it includes tests (unit tests + smoke tests)
  • the tests are executed on CI (GitHub Actions)
  • pre-commit hooks were executed locally
  • this PR requires project documentation update (handler syntax)

Author's checklist:

  • Code reviewed for misspellings
  • Code commented, especially handler execution logic
  • Tests pass locally (15/16 tests passing)

Additional information

Example task with handlers:

tasks:
  example:
    run: echo "Main task"
    success: echo "Task succeeded" > /tmp/status
    failure: echo "Task failed" > /tmp/status

Remote execution example:

tasks:
  remote-task:
    remote: test_host
    run: some_command
    success: echo "Remote success" > /tmp/remote-status
    failure: echo "Remote failure" > /tmp/remote-status

Reviewer's checklist

## Reviewer's Checklist

- [ ] I managed to reproduce the problem locally from the `main` branch
- [ ] I managed to test the new changes locally
- [ ] I confirm that the issues mentioned were fixed/resolved

@xmnlab
Copy link
Member

xmnlab commented Mar 5, 2025

thanks for working on that @Notchayan, appreciate that.

that issue was a bit old, before the implementation of hooks
the success and failure should be added into the hooks entry.

let me know if you have any questions, please.

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.

Add to the target an option for success and failure
2 participants