Skip to content

chore: release 0.6.0 merge back to development #46

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

Merged
merged 2 commits into from
May 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{".":"0.5.0"}
{".":"0.6.0"}
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [0.6.0](https://github.com/tagshelfsrl/alfred-python/compare/v0.5.0...v0.6.0) (2025-03-24)


### Features

* enhance AlfredRealTimeClient with error handling and connection callbacks ([#44](https://github.com/tagshelfsrl/alfred-python/issues/44)) ([ac7aed5](https://github.com/tagshelfsrl/alfred-python/commit/ac7aed5747c2eff300460c2c5b0ff31c808c9f5c))

## [0.5.0](https://github.com/tagshelfsrl/alfred-python/compare/v0.4.0...v0.5.0) (2024-05-20)


Expand Down
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ result = client.jobs.get("XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX")
print(result)
```

#### Get paginated jobs

```python
# Get paginated jobs
response = client.jobs.get_all(page_size=None, current_page=None)
print(response.is_empty)
print(response.result)
print(response.total)
```

#### Create job

```python
Expand Down Expand Up @@ -190,7 +200,13 @@ auth_config = AuthConfiguration({
"api_key": "AXXXXXXXXXXXXXXXXXXXXXX"
})

client = AlfredRealTimeClient(config, auth_config, verbose=True)
client = AlfredRealTimeClient(
config,
auth_config,
verbose=False,
on_callback=None,
on_connect=None
)
```

### File Events
Expand Down
18 changes: 13 additions & 5 deletions alfred/realtime/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


class AlfredRealTimeClient:
def __init__(self, config: ConfigurationDict, auth_config: AuthConfiguration, verbose=False):
def __init__(self, config: ConfigurationDict, auth_config: AuthConfiguration, verbose=False, error_callback=None, on_connect=None):
"""
Initializes the AlfredRealTimeClient class.

Expand All @@ -27,6 +27,8 @@ def __init__(self, config: ConfigurationDict, auth_config: AuthConfiguration, ve
self.config = config
self.auth_config = auth_config
self.base_url = config.get("realtime_url")
self.error_callback = error_callback
self.on_connect = on_connect

# Initialize logger
self.logger = logging.getLogger("alfred-python")
Expand All @@ -35,7 +37,6 @@ def __init__(self, config: ConfigurationDict, auth_config: AuthConfiguration, ve
"level": "DEBUG" if verbose else "INFO",
"name": "alfred-python"
})
print(self.logger.level)

# Subscribe to connection life-cycle events.
self.socket.on('connect', self.__on_connect)
Expand All @@ -55,12 +56,15 @@ def __on_connect(self):
Handles the 'connect' event.
"""
self.logger.info(f"Successfully connected to: {self.base_url}")
if self.on_connect:
self.on_connect()

def __on_disconnect(self):
"""
Handles the 'disconnect' event.
"""
self.logger.info("Disconnected from the server.")
if self.verbose:
self.logger.info("Disconnected from the server.")

def __on_connect_error(self, err):
"""
Expand All @@ -69,9 +73,12 @@ def __on_connect_error(self, err):
Args:
err (str): The error message.
"""
self.logger.info("Connection error: %s", err)
if self.verbose:
self.logger.error("Connection error: %s", err)
self.disconnect()
raise Exception(f"Failed to connect to {self.base_url}: {err}")
# trigger error callback:
if self.error_callback:
self.error_callback(err)

def __callback(self, event: Union[FileEvent, JobEvent, EventType], callback):
"""
Expand Down Expand Up @@ -122,3 +129,4 @@ def disconnect(self):
"""
self.logger.info("Closing connection...")
self.socket.disconnect()

10 changes: 10 additions & 0 deletions alfred/rest/jobs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,13 @@ def get(self, job_id: Text) -> Any:
Args:
- job_id: Unique identifier of the Job.
"""

@abstractmethod
def get_all(self, page_size: int = None, current_page: int = None) -> Any:
"""
Fetches all jobs for a company

Args:
- page_size: Number of jobs to fetch per page.
- current_page: Page number to fetch.
"""
16 changes: 16 additions & 0 deletions alfred/rest/jobs/v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,19 @@ def get(self, job_id: Text):
"""
parsed_resp, _ = self.http_client.get(f"/api/job/detail/{job_id}")
return parsed_resp

def get_all(self, page_size: int = None, current_page: int = None):
"""
Fetches all jobs for a company

Args:
- page_size: Number of jobs to fetch per page.
- current_page: Page number to fetch.
"""
params = {}
if page_size:
params["pageSize"] = page_size
if current_page:
params["currentPage"] = current_page
parsed_resp, _ = self.http_client.get("/api/job/all", params=params)
return parsed_resp
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "alfred-python"
version = "0.5.0"
version = "0.6.0"
authors = [{ name = "Tagshelf LLC", email = "support@tagshelf.com" }]
description = "Python library designed to simplify and streamline interactions with the Alfred API"
readme = "README.md"
Expand Down
Loading