Skip to content
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

Search: add Google Tasks queue path parameter #180

Merged
merged 1 commit into from
Nov 30, 2023
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
4 changes: 4 additions & 0 deletions src/semantic_search/semantic_search/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ def get_google_tasks_service_account() -> str:
return os.environ.get('GOOGLE_TASKS_SERVICE_ACCOUNT')


def get_google_tasks_queue_path() -> str:
return os.environ.get('GOOGLE_TASKS_QUEUE_PATH')


def get_api_base_url() -> str:
return os.environ.get('API_BASE_URL')

Expand Down
16 changes: 8 additions & 8 deletions src/semantic_search/semantic_search/google_tasks.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import json
from typing import Optional
from uuid import uuid4

from google.cloud import tasks_v2

from .config import index_service_endpoint, get_google_tasks_service_account
from .config import index_service_endpoint, get_google_tasks_service_account, get_google_tasks_queue_path
from .load_messages import index_whole_channel


def create_http_task_with_token(
project: str,
location: str,
queue: str,
url: str,
payload: bytes,
queue_path: Optional[str]
) -> tasks_v2.Task:
client = tasks_v2.CloudTasksClient()
# noinspection PyTypeChecker
Expand All @@ -27,10 +26,13 @@ def create_http_task_with_token(
),
)

if queue_path is None:
queue_path = "projects/develop-up/locations/us-central1/queues/semantic-search-index"

# noinspection PyTypeChecker
return client.create_task(
tasks_v2.CreateTaskRequest(
parent=client.queue_path(project, location, queue),
parent=queue_path,
task=task,
),
timeout=30,
Expand All @@ -48,11 +50,9 @@ def trigger_indexation(namespace, channel_id):

def queue_task(payload):
create_http_task_with_token(
'develop-up',
'us-central1',
'semantic-search-index',
index_service_endpoint(),
bytes(json.dumps(payload), 'utf-8'),
get_google_tasks_queue_path(),
)


Expand Down