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

chore: remove pubsub #69

Merged
merged 1 commit into from
Sep 1, 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
30 changes: 0 additions & 30 deletions apps/sql_data/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,36 +188,6 @@ def upload_data_dir(self) -> str:

def mark_as_complete(self, user=None) -> None:
self.update(modifier=user, finish_time=timezone.now())
# TODO: This should be replaced with the observer pattern.
self._publish_to_pubsub()

def _publish_to_pubsub(self) -> None:
# TODO: Implement this functionality properly and DELETE this!!!
import json
import os

from google.cloud import pubsub_v1

message_payload = json.dumps(
obj={
"org_unit_code": self.org_unit_code,
"org_unit_name": self.org_unit_name,
"content_type": self.content_type,
"extract_metadata": str(self.extract_metadata.id),
"extract_type": self.extract_metadata.name,
"chunks_count": self.chunks_count,
"upload_id": str(self.id),
"uploads_data_dir": self.upload_data_dir,
"start_time": str(self.start_time),
"finish_time": str(self.finish_time),
},
check_circular=True,
)
publisher = pubsub_v1.PublisherClient()
topic_id = os.getenv("PUB_SUB_TOPIC")
project_id = os.getenv("GOOGLE_CLOUD_PROJECT")
topic_path = publisher.topic_path(project_id, topic_id)
publisher.publish(topic_path, message_payload.encode("utf-8"))

class Meta(AbstractExtractMetadata.Meta):
verbose_name_plural = "Sql upload metadata"
7 changes: 7 additions & 0 deletions apps/sql_data/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ def setUp(self):
super().setUp()
self.sql_upload_metadata = baker.make(SQLUploadMetadata)

def test_chunks_count(self):
chunk = baker.make(
SQLUploadChunk, upload_metadata=self.sql_upload_metadata
)
chunk.save()
assert self.sql_upload_metadata.chunks_count == 1

def test_data_source_name(self):
data_source = self.sql_upload_metadata.data_source_name
data_source_name = (
Expand Down
1 change: 0 additions & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ Django~=4.2
djangorestframework~=3.14.0
environs~=9.5.0
google-auth~=2.17.1
google-cloud-pubsub~=2.15.2
openpyxl~=3.1.2
psycopg~=3.1.8
psycopg-binary~=3.1.8
Expand Down
Loading