-
Notifications
You must be signed in to change notification settings - Fork 29
agentic triggers - Gmail provider, OAuth, Pub/Sub #290
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,3 +37,22 @@ | |
| DB_HOST: str = os.environ['DB_HOST'] | ||
| DB_PORT: str = os.environ['DB_PORT'] | ||
| DB_NAME: str = os.environ['DB_NAME'] | ||
|
|
||
|
|
||
| def _required_env(name: str) -> str: | ||
| value = os.getenv(name) | ||
| if not value: | ||
| raise RuntimeError(f'Missing required environment variable: {name}') | ||
| return value | ||
|
|
||
|
|
||
| # Triggers — Gmail OAuth + Pub/Sub | ||
| GOOGLE_OAUTH_CLIENT_ID: str = _required_env('GOOGLE_OAUTH_CLIENT_ID') | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had assumed this was part of the db schema for creating triggers ? Are we using environment variables ?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should go in db, and should be part of the configuration |
||
| GOOGLE_OAUTH_CLIENT_SECRET: str = _required_env('GOOGLE_OAUTH_CLIENT_SECRET') | ||
| GOOGLE_OAUTH_REDIRECT_URI: str = _required_env('GOOGLE_OAUTH_REDIRECT_URI') | ||
| GCP_PROJECT_ID: str = _required_env('GCP_PROJECT_ID') | ||
| GMAIL_PUBSUB_TOPIC_PREFIX: str = os.getenv( | ||
| 'GMAIL_PUBSUB_TOPIC_PREFIX', 'agentic-trigger' | ||
| ) | ||
| GMAIL_PUSH_ENDPOINT_TEMPLATE: str = _required_env('GMAIL_PUSH_ENDPOINT_TEMPLATE') | ||
| GMAIL_PUBSUB_OIDC_SA_EMAIL: str = _required_env('GMAIL_PUBSUB_OIDC_SA_EMAIL') | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import asyncio | ||
| from typing import Any, Dict | ||
| from uuid import UUID | ||
|
|
||
| from common_module.log.logger import logger | ||
|
|
||
| from celery_worker.celery_app import app | ||
| from celery_worker.env import MAX_RETRIES, RETRY_DELAY | ||
| from celery_worker.worker_setup import get_services | ||
|
|
||
|
|
||
| @app.task( | ||
| name='celery_worker.tasks.trigger_event_task.process_trigger_event_task', | ||
| bind=True, | ||
| max_retries=MAX_RETRIES, | ||
| default_retry_delay=RETRY_DELAY, | ||
| ) | ||
| def process_trigger_event_task( | ||
| self, trigger_id: str, raw_payload: Dict[str, Any], push_message_id: str | ||
| ) -> Dict[str, Any]: | ||
| services = get_services() | ||
| processor = services.trigger_event_processor | ||
|
|
||
| loop = asyncio.new_event_loop() | ||
| asyncio.set_event_loop(loop) | ||
| try: | ||
| parsed_trigger_id = UUID(trigger_id) | ||
| return loop.run_until_complete( | ||
| processor.process(trigger_id=parsed_trigger_id, raw_payload=raw_payload) | ||
| ) | ||
| except ValueError: | ||
| logger.error(f'Invalid trigger_id for process_trigger_event_task: {trigger_id}') | ||
| raise | ||
| except Exception as exc: | ||
| logger.exception( | ||
| f'process_trigger_event_task failed for trigger {trigger_id} ' | ||
| f'(push_message_id={push_message_id}): {exc}' | ||
| ) | ||
| if self.request.retries < self.max_retries: | ||
| raise self.retry(exc=exc) | ||
| raise | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| finally: | ||
| pending = asyncio.all_tasks(loop) | ||
| for task in pending: | ||
| task.cancel() | ||
| try: | ||
| loop.run_until_complete(asyncio.gather(*pending, return_exceptions=True)) | ||
| except Exception: | ||
|
github-code-quality[bot] marked this conversation as resolved.
Fixed
|
||
| pass | ||
| loop.close() | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,43 @@ | ||||||||||||||||||||||||||
| FROM python:3.11-slim | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| WORKDIR /app | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| COPY --from=ghcr.io/astral-sh/uv:0.8.6 /uv /uvx /bin/ | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| RUN apt-get update && apt-get install -y \ | ||||||||||||||||||||||||||
| libpq-dev \ | ||||||||||||||||||||||||||
| gcc \ | ||||||||||||||||||||||||||
| libgl1 \ | ||||||||||||||||||||||||||
| libglib2.0-0 \ | ||||||||||||||||||||||||||
| && rm -rf /var/lib/apt/lists/* | ||||||||||||||||||||||||||
|
Comment on lines
+7
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
rg -nP --iglob '*Dockerfile*' 'apt-get\s+install\s+-y(?!\s+--no-install-recommends)'Repository: rootflo/wavefront Length of output: 613 Add
💡 Proposed fix-RUN apt-get update && apt-get install -y \
+RUN apt-get update && apt-get install -y --no-install-recommends \
libpq-dev \
gcc \
libgl1 \
libglib2.0-0 \
&& rm -rf /var/lib/apt/lists/*📝 Committable suggestion
Suggested change
🧰 Tools🪛 Trivy (0.69.3)[error] 7-12: 'apt-get' missing '--no-install-recommends' '--no-install-recommends' flag is missed: 'apt-get update && apt-get install -y libpq-dev gcc libgl1 libglib2.0-0 && rm -rf /var/lib/apt/lists/*' Rule: DS-0029 (IaC/Dockerfile) 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| COPY wavefront/server/pyproject.toml wavefront/server/uv.lock ./ | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| COPY wavefront/server/modules/common_module /app/modules/common_module | ||||||||||||||||||||||||||
| COPY wavefront/server/modules/db_repo_module /app/modules/db_repo_module | ||||||||||||||||||||||||||
| COPY wavefront/server/modules/knowledge_base_module /app/modules/knowledge_base_module | ||||||||||||||||||||||||||
| COPY wavefront/server/modules/llm_inference_config_module /app/modules/llm_inference_config_module | ||||||||||||||||||||||||||
| COPY wavefront/server/modules/agents_module /app/modules/agents_module | ||||||||||||||||||||||||||
| COPY wavefront/server/modules/plugins_module /app/modules/plugins_module | ||||||||||||||||||||||||||
| COPY wavefront/server/modules/tools_module /app/modules/tools_module | ||||||||||||||||||||||||||
| COPY wavefront/server/modules/api_services_module /app/modules/api_services_module | ||||||||||||||||||||||||||
| COPY wavefront/server/modules/triggers_module /app/modules/triggers_module | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| COPY wavefront/server/packages/flo_cloud /app/packages/flo_cloud | ||||||||||||||||||||||||||
| COPY wavefront/server/packages/flo_utils /app/packages/flo_utils | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| COPY wavefront/server/plugins/datasource /app/plugins/datasource | ||||||||||||||||||||||||||
| COPY wavefront/server/plugins/authenticator /app/plugins/authenticator | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| COPY wavefront/server/background_jobs/celery_worker /app/background_jobs/celery_worker | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| RUN uv sync --package celery-worker --frozen --no-dev | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| RUN useradd -m -u 1000 celery && \ | ||||||||||||||||||||||||||
| chown -R celery:celery /app | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| USER celery | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| WORKDIR /app/background_jobs/celery_worker | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| CMD ["uv", "run", "celery", "-A", "celery_worker.celery_app", "worker", "--loglevel=info", "--pool=solo"] | ||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will renew the subscription multiple times parallely if there are multiple pods running.