Skip to content

Commit

Permalink
Merge pull request #815 from weni-ai/hotfix/send-message-out-celery
Browse files Browse the repository at this point in the history
remove from celery task update description
  • Loading branch information
johncordeiro authored Dec 8, 2023
2 parents f76d430 + 109bbb1 commit 29932ca
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
8 changes: 8 additions & 0 deletions connect/api/v1/project/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
RequestChatsPermission,
ChatsAuthorization,
)
from connect.internals.event_driven.producer.rabbitmq_publisher import RabbitmqPublisher

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -183,6 +184,13 @@ def create(self, validated_data):

def update(self, instance, validated_data):
name = validated_data.get("name", instance.name)
description = validated_data.get("description", instance.description)
message_body = {
"project_uuid": str(instance.uuid),
"description": description
}
rabbitmq_publisher = RabbitmqPublisher()
rabbitmq_publisher.send_message(message_body, exchange="update-projects.topic", routing_key="")
celery_app.send_task(
"update_project",
args=[instance.uuid, name],
Expand Down
16 changes: 14 additions & 2 deletions connect/api/v2/projects/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,15 @@ def send_request_flow_product(self, user):
def update(self, instance, validated_data):
name = validated_data.get("name", instance.name)
description = validated_data.get("description", instance.description)
message_body = {
"project_uuid": str(instance.uuid),
"description": description
}
rabbitmq_publisher = RabbitmqPublisher()
rabbitmq_publisher.send_message(message_body, exchange="update-projects.topic", routing_key="")
celery_app.send_task(
"update_project",
args=[instance.uuid, name, description],
args=[instance.uuid, name],
)
updated_instance = super().update(instance, validated_data)
if not settings.TESTING:
Expand Down Expand Up @@ -532,9 +538,15 @@ def update(self, instance, validated_data): # pragma: no cover
instance = super().update(instance, validated_data)
name = validated_data.get("name", instance.name)
description = validated_data.get("description", instance.description)
message_body = {
"project_uuid": str(instance.uuid),
"description": description
}
rabbitmq_publisher = RabbitmqPublisher()
rabbitmq_publisher.send_message(message_body, exchange="update-projects.topic", routing_key="")
celery_app.send_task(
"update_project",
args=[instance.uuid, name, description],
args=[instance.uuid, name],
)
return instance
except Exception as error:
Expand Down
9 changes: 1 addition & 8 deletions connect/common/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,14 @@ def update_user_permission_organization(
retry_kwargs={"max_retries": 5},
retry_backoff=True,
)
def update_project(organization_uuid: str, organization_name: str, organization_description: str = None):
def update_project(organization_uuid: str, organization_name: str):
flow_instance = FlowsRESTClient()
chats = ChatsRESTClient()
chats.update_chats_project(project_uuid=organization_uuid)
flow_instance.update_project(
project_uuid=organization_uuid,
organization_name=organization_name,
)
if organization_description:
message_body = {
"project_uuid": str(organization_uuid),
"description": organization_description
}
rabbitmq_publisher = RabbitmqPublisher()
rabbitmq_publisher.send_message(message_body, exchange="update-projects.topic", routing_key="")
return True


Expand Down

0 comments on commit 29932ca

Please sign in to comment.