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(event listener): introduce BeforeJobRunsSkipIfBeforeFuncErrors as a new Eventlistener #813

Merged
merged 1 commit into from
Jan 9, 2025

Conversation

FalcoSuessgott
Copy link
Contributor

@FalcoSuessgott FalcoSuessgott commented Jan 8, 2025

What does this do?

This PR adds a new EventListener BeforeJobRunsSkipIfBeforeFuncErrors that exits job execution if the provided func returns an error

Use Case:
Im using gocron as a command wrapper for terraform to perform synthetic monitoring checks and came up with a configuration as follows:

settings:
  interval: 10s
  extra_labels:
    development: true

tests:
  vmware_vm:
    env:
      TF_VAR_content: "This is a variable"

    before_script:
      - cmd: terraform init
        retries: 2

    script:
      - cmd: terraform apply -auto-approve

    after_script:
      - cmd: terraform destroy -auto-approve

Where as the commands specified in the before_script block would be passed to BeforeJobRuns(), without this PR there was no way to stop the currents jobs execution in case of an error in any of the commands in before_script.

Introducing BeforeJobRunsSkipIfBeforeFuncErrors allows me to exit the jobs execution gracefully and reschedule to job after the given interval.

List any changes that modify/break current functionality

none

Have you included tests for your changes?

Si

Did you document any new/modified functionality?

  • Updated example_test.go
  • Updated README.md

Notes

@FalcoSuessgott FalcoSuessgott changed the title before script error feat(event listener): introduce BeforeJobError as a new Eventlistener Jan 8, 2025
@FalcoSuessgott FalcoSuessgott force-pushed the v2 branch 3 times, most recently from 7d0a1e7 to e9e532d Compare January 8, 2025 04:37
executor.go Outdated Show resolved Hide resolved
executor.go Outdated Show resolved Hide resolved
job.go Outdated Show resolved Hide resolved
Copy link
Contributor

@JohnRoesler JohnRoesler left a comment

Choose a reason for hiding this comment

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

Last thing, can you add an example to the example test file?

@FalcoSuessgott FalcoSuessgott changed the title feat(event listener): introduce BeforeJobError as a new Eventlistener feat(event listener): introduce BeforeJobRunsSkipIfBeforeFuncErrors as a new Eventlistener Jan 9, 2025
Copy link
Contributor

@JohnRoesler JohnRoesler left a comment

Choose a reason for hiding this comment

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

Nice!

@JohnRoesler JohnRoesler merged commit cc66c78 into go-co-op:v2 Jan 9, 2025
4 checks passed
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.

2 participants