Skip to content

Commit

Permalink
chore: remove pubsub (#69)
Browse files Browse the repository at this point in the history
no longer required
  • Loading branch information
saladgg authored and kennedykori committed Sep 1, 2023
1 parent bd83544 commit b1aa91d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 31 deletions.
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

0 comments on commit b1aa91d

Please sign in to comment.