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

Single Instance Tasks #22

Merged
merged 5 commits into from
Mar 16, 2024
Merged

Single Instance Tasks #22

merged 5 commits into from
Mar 16, 2024

Conversation

madflojo
Copy link
Owner

@madflojo madflojo commented Mar 15, 2024

This expands on the idea behind #21 with a slightly different implementation approach.

Summary by CodeRabbit

  • New Features
    • Introduced a RunSingleInstance option for tasks to control execution instances, ensuring tasks marked as such run only once concurrently.
  • Bug Fixes
    • Improved task execution logic with enhanced mutex handling for better concurrency control.
  • Documentation
    • Updated the README to reflect the change in coverage reporting from Coveralls to Codecov.
  • Refactor
    • Upgraded to Go version 1.18 for better performance and stability.
    • Switched from Coveralls to Codecov for test coverage reporting in GitHub Actions.
    • Enhanced task struct and testing benchmarks for more efficient execution and testing.

Copy link

coderabbitai bot commented Mar 15, 2024

Walkthrough

The update enhances the tasks repository by refining its testing workflow and task management logic. It shifts coverage reporting from Coveralls to Codecov, upgrades to Go 1.18, and optimizes task execution with mutex adjustments and new fields in the Task struct. Moreover, it adjusts error handling in tests and introduces safeguards for single-instance task execution, ensuring robustness and efficiency in task handling and monitoring.

Changes

File(s) Summary
.github/workflows/tests.yml, README.md Transitioned coverage reporting from Coveralls to Codecov; updated Go version in GitHub Actions.
tasks.go Enhanced task struct with sync.RWMutex, added RunSingleInstance control, and updated methods.
tasks_benchmarks_test.go, tasks_test.go Adjusted error handling in tests; added single-instance task test with a custom Counter type.

Poem

🐰✨
In the land of code and byte,
Changes come both day and night.
Mutex locks and tests refined,
Single tasks, uniquely timed.
From Coveralls to Codecov's embrace,
Our tasks march on, a steady pace.
🚀💾

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@madflojo madflojo marked this pull request as ready for review March 15, 2024 16:08
Copy link

codecov bot commented Mar 15, 2024

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 2edc60e and 9487524.
Files ignored due to path filters (1)
  • go.mod is excluded by: !**/*.mod
Files selected for processing (5)
  • .github/workflows/tests.yml (2 hunks)
  • README.md (1 hunks)
  • tasks.go (6 hunks)
  • tasks_benchmarks_test.go (1 hunks)
  • tasks_test.go (26 hunks)
Files skipped from review due to trivial changes (1)
  • tasks_benchmarks_test.go
Additional comments: 15
.github/workflows/tests.yml (2)
  • 22-22: The update to Go version 1.18 is appropriate for keeping the project dependencies up-to-date.
  • 33-37: Switching from Coveralls to Codecov for coverage reporting is correctly implemented. Ensure that the CODECOV_TOKEN secret is properly set in the repository settings.
README.md (1)
  • 3-3: Updating the coverage badge URL to point to Codecov aligns with the switch to Codecov for coverage reporting. Ensure the token in the URL is correct and corresponds to the project on Codecov.
tasks.go (4)
  • 94-94: Replacing sync.Mutex with sync.RWMutex in the Task struct is a good optimization for concurrent access patterns.
  • 120-126: The addition of the RunSingleInstance field is well-implemented and documented, aligning with the PR objectives to control single instance task executions.
  • 159-160: The running mutex addition is crucial for managing the execution state of single instance tasks, ensuring that only one instance runs at a given time.
  • 371-385: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [374-403]

The update to the execTask method correctly incorporates logic for handling single instance tasks, utilizing the running mutex to prevent concurrent executions.

tasks_test.go (8)
  • 29-54: The Counter type and its methods (Inc, Dec, Val) are well-implemented with proper locking mechanisms to ensure thread safety. This is crucial for accurately testing the single instance task functionality.
  • 81-81: Modifying the ErrFunc to ignore the error parameter simplifies the test cases where error handling is not the focus. This change makes the tests cleaner and more focused on the task execution logic.
  • 90-90: Similar to the previous comment, modifying the ErrFunc within a task that includes a context is a good simplification for tests not concerned with error handling specifics.
  • 100-100: The modification to ErrFuncWithTaskContext to ignore both the TaskContext and the error parameter is consistent with the approach taken for ErrFunc. This keeps the focus on the functionality being tested rather than error handling.
  • 110-110: Again, ignoring parameters in ErrFuncWithTaskContext for tasks without a context but with context functions simplifies the test setup. This consistency in handling error functions across different test cases is good for maintainability.
  • 299-299: Explicitly stating that ErrFunc should not be called in this test case is a good practice. It ensures that the test will fail if the error handling logic is incorrectly invoked, which is important for verifying task execution behavior.
  • 314-318: The approach of ensuring ErrFuncWithTaskContext is not called unless there's an error is consistent with the previous comment. This helps in verifying that error handling logic is correctly separated from the main task execution path.
  • 355-355: This test case correctly verifies that the StartAfter time is respected by ensuring the task does not execute before the specified time. This is crucial for tasks that need to be scheduled to run in the future.

tasks_test.go Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 9487524 and d16104a.
Files selected for processing (1)
  • tasks_test.go (26 hunks)
Files skipped from review as they are similar to previous changes (1)
  • tasks_test.go

@madflojo madflojo merged commit e219a13 into main Mar 16, 2024
4 checks passed
@madflojo madflojo deleted the singleinstance branch March 16, 2024 12:19
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