saga-framework icon indicating copy to clipboard operation
saga-framework copied to clipboard

Passing parameters to the async saga

Open jairoguerra89 opened this issue 3 years ago • 0 comments

Hey guys

This is probably a dumb question, I was wondering how can I pass a parameter or a dict or whatever to an AsyncSaga? check this out

`

class CreatePropertySaga(AsyncSaga):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.steps = [
            AsyncStep(
                name="create_property",
                action=self.create_property,
                base_task_name=create_property_message.TASK_NAME,
                queue=messaging.COMMANDS_QUEUE,
                on_success=self.create_property_on_success,
                on_failure=self.create_property_on_failure,
            ),
        ]
    
    def create_property(self, current_step: AsyncStep):
        self.send_message_to_other_service(
            current_step,
            asdict(
                create_property_message.Payload(
                    street_address=self.request_data["streetAddres"],
                    city=self.request_data["city"],
                    state=self.request_data["state"],
                    zip_code=self.request_data["zipCode"]
                )
            ),
        )

    def create_property_on_success(self, current_step: BaseStep, payload: dict):
        logger.info("Created the property successfully.")
        logger.info(f"Result = {payload}")

    def create_property_on_failure(self, current_step: BaseStep, payload: dict):
        logger.info("An error ocurred while trying to create the property.")
        logger.info(f"Result = {payload}")`

jairoguerra89 avatar May 22 '21 10:05 jairoguerra89