You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Run `pre-commit install`. For more details, check out Development > Git hooks.
51
55
@@ -66,6 +70,40 @@ automatically [pip](https://pip.pypa.io/en/stable/) as well.
66
70
- Open `http://127.0.0.1:5000/` in a browser. You will find in the presented UI
67
71
a link to the swagger.json with the definition of the api.
68
72
73
+
#### Handling Cosmos DB triggers for creating events with time_tracker_events
74
+
The project `time_tracker_events` is an Azure Function project. Its main responsibility is to respond to calls related to
75
+
events, like those [triggered by Change Feed](https://docs.microsoft.com/en-us/azure/cosmos-db/change-feed-functions).
76
+
Every time a write action (`create`, `update`, `soft-delete`) is done by CosmosDB, thanks to [bindings](https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-cosmosdb?toc=%2Fazure%2Fcosmos-db%2Ftoc.json&bc=%2Fazure%2Fcosmos-db%2Fbreadcrumb%2Ftoc.json&tabs=csharp)
77
+
these functions will be called. You can also run them in your local machine:
78
+
79
+
- You must have the [Azure CLI](https://docs.microsoft.com/en-us/cli/azure/get-started-with-azure-cli?view=azure-cli-latest)
80
+
and the [Azure Functions Core Tools](https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local?tabs=macos%2Ccsharp%2Cbash)
81
+
installed in your local machine.
82
+
- Be sure to [authenticate](https://docs.microsoft.com/en-us/cli/azure/authenticate-azure-cli?view=azure-cli-latest)
83
+
with the Azure CLI if you are not.
84
+
```bash
85
+
az login
86
+
```
87
+
- Execute the project
88
+
```bash
89
+
cd time_tracker_events
90
+
source run.sh
91
+
```
92
+
You will see that a large console log will appear ending with a message like
93
+
```log
94
+
Now listening on: http://0.0.0.0:7071
95
+
Application started. Press Ctrl+C to shut down.
96
+
```
97
+
- Now you are ready to start generating events. Just execute any change in your API and you will see how logs are being
98
+
generated by the console app you ran before. For instance, this is the log generated when I restarted a time entry:
99
+
```log
100
+
[04/30/2020 14:42:12] Executing 'Functions.handle_time_entry_events_trigger' (Reason='New changes on collection time_entry at 2020-04-30T14:42:12.1465310Z', Id=3da87e53-0434-4ff2-8db3-f7c051ccf9fd)
101
+
[04/30/2020 14:42:12] INFO: Received FunctionInvocationRequest, request ID: 578e5067-b0c0-42b5-a1a4-aac858ea57c0, function ID: c8ac3c4c-fefd-4db9-921e-661b9010a4d9, invocation ID: 3da87e53-0434-4ff2-8db3-f7c051ccf9fd
In this API we are requiring authenticated users using JWT. To do so, we are using the library
71
109
[PyJWT](https://pypi.org/project/PyJWT/), so in every request to the API we expect a header `Authorization` with a format
@@ -99,6 +137,16 @@ following notes regarding to the manipulation of the data from and towards the A
99
137
- The [recommended](https://docs.microsoft.com/en-us/azure/cosmos-db/working-with-dates#storing-datetimes) format for
100
138
DateTime strings in Azure Cosmos DB is `YYYY-MM-DDThh:mm:ss.fffffffZ` which follows the ISO 8601 **UTC standard**.
101
139
140
+
The Azure function project `time_tracker_events` also have some constraints to have into account. It is recommended that
141
+
you read the [Azure Functions Python developer guide](https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-python#folder-structure).
142
+
143
+
If you require to deploy `time_tracker_events` from your local machine to Azure Functions, you can execute:
144
+
145
+
```bash
146
+
func azure functionapp publish time-tracker-events --build local
147
+
```
148
+
149
+
102
150
## Development
103
151
104
152
### Git hooks
@@ -254,6 +302,8 @@ the win.
254
302
-[Swagger](https://swagger.io/) for documentation and standardization, taking into account the
255
303
[API import restrictions and known issues](https://docs.microsoft.com/en-us/azure/api-management/api-management-api-import-restrictions)
for making `time_tracker_events` to handle the triggers [generated by our Cosmos DB database throw Change Feed](https://docs.microsoft.com/bs-latn-ba/azure/cosmos-db/change-feed-functions).
0 commit comments