Skip to content

Commit 0024ea0

Browse files
authored
Add usage examples in README (#70)
* Add os limitations in docs * Add usage examples in README
1 parent b51af0a commit 0024ea0

3 files changed

Lines changed: 72 additions & 0 deletions

File tree

README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,76 @@ FluxQueue is a task queue for Python that gets out of your way. The Rust core ma
3333
- Redis server
3434
- Linux (Windows and macOS support coming soon)
3535

36+
## Installation
37+
38+
```bash
39+
pip install fluxqueue[cli]
40+
```
41+
42+
## Example
43+
44+
`tasks.py`
45+
46+
```py
47+
from fluxqueue import FluxQueue
48+
49+
# Create a FluxQueue instance (defaults to redis://127.0.0.1:6379)
50+
fluxqueue = FluxQueue()
51+
52+
# Define a task using the @fluxqueue.task decorator
53+
@fluxqueue.task()
54+
def send_email(to: str, subject: str, body: str):
55+
print(f"Sending email to {to}")
56+
print(f"Subject: {subject}")
57+
print(f"Body: {body}")
58+
```
59+
60+
## Enqueue Tasks
61+
62+
Call the decorated function to enqueue it. The function returns immediately, the actual work happens in the background:
63+
64+
```python
65+
# Enqueue the task
66+
send_email("user@example.com", "Hello", "This is a test email")
67+
```
68+
69+
The task is now in the queue, waiting to be processed by a worker.
70+
71+
## Async Tasks
72+
73+
FluxQueue supports async functions too. Just define an async function and use the same decorator:
74+
75+
```python
76+
@fluxqueue.task()
77+
async def process_data(data: dict):
78+
# Your async processing logic
79+
result = await some_async_operation(data)
80+
return result
81+
82+
# Enqueue it (use await in async contexts)
83+
await process_data({"key": "value"})
84+
```
85+
86+
## Installing the worker
87+
88+
In order the tasks to be executed you need to run a fluxqueue worker, you need to install the worker on your system with:
89+
90+
```bash
91+
fluxqueue worker install
92+
```
93+
94+
It picks the latest released worker based on your python version and installs it. You can also pass `--version` argument to specify the version you want to install.
95+
96+
## Running the worker
97+
98+
Running the worker is straightforward:
99+
100+
```bash
101+
fluxqueue start --tasks-module-path tasks
102+
```
103+
104+
In order the worker to disover your tasks you need to pass `--tasks-module-path` argument with the path to the tasks module. For more information please view the [documentation](https://fluxqueue.ccxlv.dev/tutorial/defininig_and_exposing_tasks).
105+
36106
## License
37107

38108
FluxQueue is licensed under the Apache-2.0 license. See [LICENSE](LICENSE) for details.

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ FluxQueue is a task queue for Python that gets out of your way. The Rust core ma
3434

3535
- Python 3.11, 3.12, or 3.13
3636
- Redis server
37+
- Linux (Windows and macOS support coming soon)
3738

3839
## Getting Started
3940

docs/tutorial/installation.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ FluxQueue has two parts: the Python client library for enqueueing tasks, and the
66

77
- Python 3.11, 3.12, or 3.13
88
- Redis server running and accessible
9+
- Linux (Windows and macOS support coming soon)
910

1011
## Install the Client Library
1112

0 commit comments

Comments
 (0)