Skip to content

Refactors config to accept mapping, removes INI support#8

Merged
ochui merged 4 commits intomainfrom
feat/migrate-from-config-file
Mar 24, 2026
Merged

Refactors config to accept mapping, removes INI support#8
ochui merged 4 commits intomainfrom
feat/migrate-from-config-file

Conversation

@ochui
Copy link
Copy Markdown
Member

@ochui ochui commented Mar 24, 2026

Updates configuration handling to use a Python mapping instead of an INI file, simplifying initialization and validation. Removes all file-based config logic, adjusts documentation and tests accordingly, and improves type safety for clustered Redis config. Enhances maintainability and reduces test setup complexity.

Summary by CodeRabbit

  • Documentation

    • Quickstart and README updated to show passing a Python dict as configuration instead of loading from a file.
  • Refactor

    • Configuration now provided as in-memory mappings to FQ at construction; file-based config loading and reload support removed; default file-based config removed.
  • Tests

    • Tests updated to use centralized in-memory test config and the public initialize/close APIs.
  • Bug Fixes

    • Stronger configuration validation with clearer error messages.

ochui added 2 commits March 24, 2026 17:40
Updates configuration handling to use a Python mapping instead of an INI file,
simplifying initialization and validation. Removes all file-based config logic,
adjusts documentation and tests accordingly, and improves type safety for
clustered Redis config. Enhances maintainability and reduces test setup
complexity.
Copilot AI review requested due to automatic review settings March 24, 2026 16:47
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 24, 2026

Warning

Rate limit exceeded

@ochui has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 6 minutes and 49 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8f57757c-7d39-4193-b02f-9a66bc7f0146

📥 Commits

Reviewing files that changed from the base of the PR and between 18ecef8 and 2968d71.

📒 Files selected for processing (1)
  • pyproject.toml
📝 Walkthrough

Walkthrough

Migrates FQ from INI file-based configuration to in-memory Python mappings. FQ.__init__ now accepts a validated config mapping (required redis and fq sections); file-loading and reload APIs removed. README and tests updated to use build_test_config() and eliminate filesystem config files.

Changes

Cohort / File(s) Summary
Core config & init
src/fq/queue.py
FQ.__init__ signature changed to accept a config Mapping; added validation/normalization for redis and fq sections and option types; removed file-based _load_config and reload_config; redis/lua initialization reads from self.config.
Removed default config file
src/fq/default.conf
Deleted default INI configuration file previously providing fq and redis defaults.
Documentation
README.md
Examples and Quickstart revised to show building a Python config dict and calling FQ(config) instead of loading from an INI file; removed note about matching tests/test.conf.
Test config factory
tests/config.py, tests/test.conf
Added tests/config.py with TEST_CONFIG and build_test_config(); removed INI tests/test.conf.
Test updates
tests/test_edge_cases.py, tests/test_func.py, tests/test_queue.py
Replaced filesystem-based config setup with build_test_config(); updated tests to construct FQ with dicts, use public initialize()/close() APIs, and added/adjusted validation/error-path tests (invalid types, non-boolean clustered, missing keys).

Sequence Diagram(s)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Poem

🐇 I swapped the files for tidy dicts,

no temp-file scurry, no fragile scripts.
Configs snug in memory, ready to play —
the queue hops forward, coding the day! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 64.52% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: replacing file-based INI configuration with Python mapping-based configuration and removing INI support.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/migrate-from-config-file

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

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 refactors FQ’s configuration system to accept an in-memory Python mapping (dict-like) instead of reading an INI file, removing file-based config handling and updating tests/docs accordingly.

Changes:

  • Replace INI file parsing with Mapping-based config validation/normalization in FQ.
  • Update tests to build config dictionaries via a shared build_test_config() helper and use FQ.close().
  • Remove bundled INI config files and update README examples to reflect mapping-based configuration.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/fq/queue.py Switches constructor to accept a mapping, removes INI loading/reload, and reads config from dict sections.
tests/config.py Adds shared test config + helper to simplify per-test overrides.
tests/test_queue.py Updates setup/teardown to use mapping config and close().
tests/test_func.py Removes temp config-file creation and switches to mapping-based config setup.
tests/test_edge_cases.py Adjusts edge-case coverage for mapping config (including clustered boolean validation).
README.md Updates configuration and usage examples to pass a Python mapping.
tests/test.conf Removes INI test config fixture.
src/fq/default.conf Removes default INI config file.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +64 to +72
fq_config = self.config["fq"]
redis_config = self.config["redis"]

self._key_prefix = self._config.get("redis", "key_prefix")
self._job_expire_interval = int(self._config.get("fq", "job_expire_interval"))
self._default_job_requeue_limit = int(
self._config.get("fq", "default_job_requeue_limit")
)
self._key_prefix = redis_config["key_prefix"]
self._job_expire_interval = int(fq_config["job_expire_interval"])
self._default_job_requeue_limit = int(fq_config["default_job_requeue_limit"])

redis_connection_type = self._config.get("redis", "conn_type")
db = self._config.get("redis", "db")
redis_connection_type = redis_config["conn_type"]
db = redis_config["db"]
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

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

_initialize() indexes directly into fq_config / redis_config for required keys (e.g., redis_config["key_prefix"], fq_config["job_expire_interval"]). If a caller omits a key, this will raise a raw KeyError instead of an FQException, which makes misconfiguration harder to diagnose and is inconsistent with the rest of the error surface. Consider explicitly validating required keys (and basic types) up front and raising FQException with a clear path like redis.key_prefix / fq.job_expire_interval when missing/invalid.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown

@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.

🧹 Nitpick comments (1)
src/fq/queue.py (1)

67-72: Consider wrapping int() conversions to provide clearer error messages.

Direct int() calls on config values will raise ValueError with a generic message if the value is not convertible. Since these are user-provided config values, a friendlier error would help debugging.

💡 Optional: Add validation helper for integer config values
+def _get_int_config(config, key, context):
+    try:
+        return int(config[key])
+    except (ValueError, TypeError) as e:
+        raise FQException(f"{context}.{key} must be an integer") from e
+
 async def _initialize(self):
     """Read the FQ configuration and set up redis + Lua scripts."""
     fq_config = self.config["fq"]
     redis_config = self.config["redis"]

     self._key_prefix = redis_config["key_prefix"]
-    self._job_expire_interval = int(fq_config["job_expire_interval"])
-    self._default_job_requeue_limit = int(fq_config["default_job_requeue_limit"])
+    self._job_expire_interval = _get_int_config(fq_config, "job_expire_interval", "fq")
+    self._default_job_requeue_limit = _get_int_config(fq_config, "default_job_requeue_limit", "fq")
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/fq/queue.py` around lines 67 - 72, Wrap the direct int() conversions for
fq_config["job_expire_interval"] and fq_config["default_job_requeue_limit"] in a
small validation step that catches ValueError and raises a clearer, contextual
error; e.g., create or use a helper like validate_int_config(name, value,
default=None) and replace the assignments to self._job_expire_interval and
self._default_job_requeue_limit so they call the helper (referencing fq_config
and the keys "job_expire_interval"/"default_job_requeue_limit"); ensure the
helper includes the config key name and original invalid value in the raised
exception message to aid debugging.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/fq/queue.py`:
- Around line 67-72: Wrap the direct int() conversions for
fq_config["job_expire_interval"] and fq_config["default_job_requeue_limit"] in a
small validation step that catches ValueError and raises a clearer, contextual
error; e.g., create or use a helper like validate_int_config(name, value,
default=None) and replace the assignments to self._job_expire_interval and
self._default_job_requeue_limit so they call the helper (referencing fq_config
and the keys "job_expire_interval"/"default_job_requeue_limit"); ensure the
helper includes the config key name and original invalid value in the raised
exception message to aid debugging.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0011d409-dabd-4f97-b5b1-b9ce07b60630

📥 Commits

Reviewing files that changed from the base of the PR and between b37ac71 and 5667514.

📒 Files selected for processing (8)
  • README.md
  • src/fq/default.conf
  • src/fq/queue.py
  • tests/config.py
  • tests/test.conf
  • tests/test_edge_cases.py
  • tests/test_func.py
  • tests/test_queue.py
💤 Files with no reviewable changes (2)
  • src/fq/default.conf
  • tests/test.conf

Strengthens configuration validation by raising descriptive errors
for missing or invalid config values during object construction,
ensuring misconfigurations are caught early. Updates tests to
reflect the new validation logic and error paths, improving
clarity and robustness of error handling.
Copy link
Copy Markdown

@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.

🧹 Nitpick comments (1)
src/fq/queue.py (1)

156-159: Consider simplifying the clustered flag handling.

The current pattern reads clustered twice when it exists:

if "clustered" in redis_config:
    isclustered = redis_config["clustered"]

This is correct but could be slightly cleaner using .get() with a default.

♻️ Optional simplification
-            isclustered = False
-            if "clustered" in redis_config:
-                isclustered = redis_config["clustered"]
+            isclustered = redis_config.get("clustered", False)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/fq/queue.py` around lines 156 - 159, Replace the explicit membership
check and assignment for the clustered flag with a single get call: instead of
testing "clustered" in redis_config and then setting isclustered, set
isclustered = redis_config.get("clustered", False) in the branch handling
redis_connection_type == "tcp_sock" (referencing redis_connection_type,
isclustered, and redis_config).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/fq/queue.py`:
- Around line 156-159: Replace the explicit membership check and assignment for
the clustered flag with a single get call: instead of testing "clustered" in
redis_config and then setting isclustered, set isclustered =
redis_config.get("clustered", False) in the branch handling
redis_connection_type == "tcp_sock" (referencing redis_connection_type,
isclustered, and redis_config).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cc84d692-0c37-43bd-87aa-e6a6ad1177d3

📥 Commits

Reviewing files that changed from the base of the PR and between 5667514 and 18ecef8.

📒 Files selected for processing (4)
  • src/fq/queue.py
  • tests/test_edge_cases.py
  • tests/test_func.py
  • tests/test_queue.py

@ochui ochui merged commit 0414bea into main Mar 24, 2026
5 checks passed
@ochui ochui deleted the feat/migrate-from-config-file branch March 24, 2026 17:14
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