danielgerlag / conductor

Distributed workflow server
MIT License
532 stars 98 forks source link

Workflow triggered by event is not working #27

Closed smadurange closed 4 years ago

smadurange commented 4 years ago

Hi, I created a workflow definition using the following call:

curl --location --request POST 'http://localhost:5000/api/Definition' \
--header 'Content-Type: application/json' \
--data-raw '{
    "Id": "AutomaticReply",
    "Steps": [
        {
            "Id": "OnMoReceived",
            "StepType": "While",
            "Do": [[
                {
                    "Id": "WaitForMo",
                    "StepType": "WaitFor",
                    "Inputs": {
                        "EventName": "MoReceived",
                        "EventKey": "MOIN",
                        "EffectiveDate": "DateTime.Now"
                    },
                    "Outputs": {
                        "Mo": "step.Data"
                    },
                    "NextStepId": "SendMt"
                },
                {
                    "Id": "SendMt",
                    "StepType": "HttpRequest",
                    "Inputs": {
                        "BaseUrl": "http://localhost:5006/api/v1/send/",
                        "Resource": "message",
                        "Method": "POST",
                        "Headers":{
                            "@Authorization": "Bearer XXX",
                            "@Content-Type": "application/json"
                        },
                        "Body": {
                            "destination": "data.Mo.Source",
                            "text": "data.Mo.Text"
                        }
                    }
                }
            ]]
        }
    ]
}'

And I received the expected 204 response. I can see the workflow definition saved to the database. Then I started the workflow using

curl --location --request POST 'http://localhost:5000/api/workflow/AutomaticReply' \
--header 'Content-Type: application/json' \
--data-raw '{

}'

I received the response as expected:

Data: {}
DefinitionId: AutomaticReply
EndTime: null
Reference: null
StartTime: 2020-09-09T07:21:31.8100000Z
Status: Runnable
Version: 1
WorkflowId: 5f58827ba91412682c7ba41b

Then, I wanted to check the status of this workflow. Here, something strange happens. I expected the workflow to be running, but the status I got back was that it was completed. My curl request:

curl --location --request GET 'http://localhost:5000/api/workflow/5f58827ba91412682c7ba41b'

And the response I received was

Data: {}
DefinitionId: AutomaticReply
EndTime: 2020-09-09T07:21:31.9070000Z
Reference: null
StartTime: 2020-09-09T07:21:31.8100000Z
Status: Complete
Version: 1
WorkflowId: 5f58827ba91412682c7ba41b

In any case, I tried raising the event using the http request:

curl --location --request POST 'http://localhost:5000/api/event/MoReceived/MOIN' \
--header 'Content-Type: application/json' \
--data-raw '{
    "Destination": "xxxxxxxxx",
    "Source": "xxxxxxxx",
    "Text": "Hello, world!"
}'

To which I got back the 204 response.

However, I did not receive any request as expected to http://localhost:5006/api/v1/send/message. I don't see any errors on the console. In the database, I see the entry:

{
    "_id": "5f5882a7a91412682c7ba41c",
    "EventName": "MoReceived",
    "EventKey": "MOIN",
    "EventData": {
        "Destination": "xxxxxxx",
        "Source": "xxxxx",
        "Text": "Hello, world!"
    },
    "EventTime": {
        "$date": {
            "$numberLong": "1599636135337"
        }
    },
    "IsProcessed": true
}

What am I doing wrong? Thanks.