Skip to content

Commit

Permalink
fix: PubSub message to JSON conversion (#37)
Browse files Browse the repository at this point in the history
Fix PubSub message to JSON conversion bug introduced on [#36](#36).
  • Loading branch information
kennedykori committed Sep 11, 2022
1 parent 0f9bf8a commit 4962190
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions apps/sql_data/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,37 +193,31 @@ def mark_as_complete(self, user=None) -> None:

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

from google.cloud import pubsub_v1

data = {
"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),
}
message_payload = io.BytesIO()
json.dump(
data,
message_payload,
ensure_ascii=True,
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,
skipkeys=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.getvalue())
publisher.publish(topic_path, message_payload.encode("utf-8"))

class Meta(AbstractExtractMetadata.Meta):
verbose_name_plural = "Sql upload metadata"

0 comments on commit 4962190

Please sign in to comment.