moclojer / clj-rq

RQ (Redis Queue) is a simple Clojure package for queueing jobs and processing them in the background with workers. It is backed by Redis and it is designed to have a low barrier to entry
MIT License
16 stars 2 forks source link

API improvement refactor #5

Closed J0sueTM closed 4 months ago

J0sueTM commented 4 months ago

closes #4

Summary by CodeRabbit

coderabbitai[bot] commented 4 months ago

[!WARNING]

Review failed

The pull request is closed.

Walkthrough ## Walkthrough The codebase has undergone significant refactoring to improve the clarity and consistency of the API for queue operations and pub/sub mechanisms. Key changes include renaming functions for better state-change indication, splitting functions into more focused roles, improving logging, and enhancing error handling. Additionally, new files and workflows have been introduced for better testing and development practices. ## Changes | Files/Patterns | Summary | |-----------------------------------------------------|----------------------------------------------------------------------------------| | `.gitignore` | Included `redis` directory. | | `deps.edn` | Updated with a new dependency on `org.clojure/tools.logging` and corrected whitespace. | | `docker/docker-compose.yml` | Added configuration for a Redis service. | | `src/com/moclojer/rq.clj` | Refactored connection handling with Redis and renamed client functions. | | `src/com/moclojer/rq/pubsub.clj` | Refactored pub/sub functionality, enhanced logging and error handling. | | `src/com/moclojer/rq/queue.clj` | Introduced new functions `push!`, `pop!`, `llen`, and logging enhancements. | | `src/com/moclojer/rq/utils.clj` | Introduced new utility functions for pattern handling. | | `test/com/moclojer/rq/pubsub_test.clj` | Added test cases for pub/sub system. | | `test/com/moclojer/rq/queue_test.clj` | Added test cases for queue operations. | | `test/com/moclojer/rq_test.clj` | Introduced tests for Redis client creation. | | `test/com/moclojer/test_utils.clj` | Added `gen-message` function for generating test data. | | `README.md` | Updated function calls and added new examples reflecting API changes. | | `.github/workflows/tests.yml` | Introduced a GitHub Actions workflow for testing on pushes and pull requests. | ## Sequence Diagram(s) ```mermaid sequenceDiagram participant Client as User Client participant Redis as Redis Server participant Queue as Queue Module participant PubSub as PubSub Module Note over Client, Queue: Queue Operation Flow Client->>Queue: push!(message) Queue->>Redis: Set Data Redis-->>Queue: Acknowledge Queue-->>Client: Job Queued Note over Client, PubSub: Pub/Sub Operation Flow Client->>PubSub: publish!(message) PubSub->>Redis: Publish Data Redis-->>PubSub: Acknowledge PubSub-->>Client: Message Published ``` ## Assessment against linked issues | Objective | Addressed | Explanation | |------------------------------------------------------------------------|------------|-----------------------------------------| | Functions named as verbs indicating state changes (#4) | ✅ | | | Separate queue and pub/sub functionalities clearly (#4) | ✅ | | ## Poem > In lines of code where changes dance, > Functions now with clearer stance. > Push and pop, they surely know, > How to make our queues just flow. > Redis sings with tests it meets, > GitHub Actions runs and greets. > In this code, so neatly spun, > Celebrate, for progress won! 🎉🐇

[!TIP]

AI model upgrade ## `gpt-4o` model for reviews and chat is now live OpenAI claims that this model is better at understanding and generating code than the previous models. Please join our [Discord Community](https://discord.com/invite/GsXnASn26c) to provide any feedback or to report any issues.

Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `Generate unit testing code 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 testing code 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 testing code.` - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.` - `@coderabbitai help me debug CodeRabbit configuration file.` 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 an incremental review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai full review` to do a full review from scratch and review all the files again. - `@coderabbitai summary` to regenerate the summary of the PR. - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository. - `@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. - Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information. - 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/schema.v2.json` ### Documentation and Community - Visit our [Documentation](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
J0sueTM commented 4 months ago

@coderabbitai review

coderabbitai[bot] commented 4 months ago
Actions performed Review triggered. > Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.
avelino commented 4 months ago

@coderabbitai wtf, do you approve a PR without having CI (running tests automatically)? could you write a GitHub action running the tests automatically on each pull request or push

coderabbitai[bot] commented 4 months ago

@avelino, I apologize for the oversight. I will create a GitHub Action to run the tests automatically on each pull request or push.

name: Run Tests

on:
  push:
    branches:
      - main
      - 'refs/tags/*'
  pull_request:
    branches:
      - main

jobs:
  test:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout code
      uses: actions/checkout@v2

    - name: Set up Java
      uses: actions/setup-java@v1
      with:
        java-version: '11'

    - name: Install dependencies
      run: |
        clojure -Sdeps '{:deps {org.clojure/clojure {:mvn/version "1.10.3"} org.clojure/tools.logging {:mvn/version "1.3.0"}}}'
        clojure -Sdeps '{:deps {redis.clients/jedis {:mvn/version "3.5.2"}}}'

    - name: Run tests
      run: clojure -A:test

This GitHub Action will ensure that tests are run automatically on each pull request or push to the main branch.

[add_learning] Make sure to always have CI (Continuous Integration) setup for running tests automatically on each pull request or push before approving a PR.

Actions performed Review triggered. > Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.
avelino commented 4 months ago

@J0sueTM it's worth placing the diagram that @coderabbitai (in mermaid) and putting it in the readme

coderabbitai[bot] commented 4 months ago

@avelino, I agree that adding a diagram to the README will help users understand the refactored API better. Here is a Mermaid diagram illustrating the new structure of the queue and pub/sub operations:

classDiagram
    class Queue {
        +push!(client, queue-name, message, options)
        +pop!(client, queue-name, options)
        +llen(client, queue-name, options)
    }

    class PubSub {
        +publish!(client, channel, message)
        +archive!(client, channel, message)
        +unarchive!(client, channel, message)
        +subscribe!(client, on-msg-fn, channels)
    }

To add this diagram to the README, you can include the following snippet:

## API Structure

```mermaid
classDiagram
    class Queue {
        +push!(client, queue-name, message, options)
        +pop!(client, queue-name, options)
        +llen(client, queue-name, options)
    }

    class PubSub {
        +publish!(client, channel, message)
        +archive!(client, channel, message)
        +unarchive!(client, channel, message)
        +subscribe!(client, on-msg-fn, channels)
    }


This will render the diagram in the README, providing a clear visual representation of the API structure.

[add_learning]
Consider adding diagrams in Mermaid format to the README to illustrate complex API structures and improve documentation clarity.

<details>
<summary>Actions performed</summary>

Review triggered.

> Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

</details>