-
Notifications
You must be signed in to change notification settings - Fork 1
SamplesManager
Samples Manager is a microservice responsible for storing content items (Code sample or Code samples items) to Kentico Kontent. The service is written in Javascript as an Azure Durable function with an EventGrid trigger.
Samples Manager has been created in order to handle synchronization between GitHub code and code sample items in Kentico Kontent. It consumes data prepared by GitHub Reader which extract the samples from GitHub files and store them in the Azure Blob Storage. Samples Manager responds to changes in the Azure Blob Storage and then updates content items in Kentico Kontent project accordingly.
The EventGrid trigger of Azure Blob Storage provides a way to immediately run the service after the creation of new blob in the Azure Blob Storage.
Samples Manager is invoked after the change in the blob storage. GitHub Reader adds new blob into the Azure Blob Storage and event grid event is sent to invoke Samples Manager. An example code fragment blob in JSON can look like this:
{
"codeFragments": [
{
"identifier":"test_codename",
"content":"const KenticoKontent = require('kentico-kontent-delivery');",
"language":"javascript",
"platform":"javascript",
"status":"added",
"codename":"test_codename_js"
}
],
"mode":"update"
}
Value of mode
stored in the blob can be either update
or initialize
and it defines the behavior of the Samples Manager. The initialize mode is designed to clear stored information in the table storage and process all of the code fragments from the blob, which is intended to be done by a user to make sure there is no inconsistency between code samples in GitHub repository and code samples in Kentico Kontent. The update mode is designed to perform modification of the content in Kentico Kontent after processed commit by GitHub Reader.
All code fragments loaded from blob are divided into the chunks of size 10. The reason for splitting fragments into the chunks is the optimization of the amount of Kentico Kontent CM API calls and the run time of function. Timeout of Azure Function is 5 minutes - Azure Durable Function brings us an benefit of generator approach which provides us longer run of function than 5 minutes.
CleanCodeSampleInfo is an Azure Function invoked when blob with mode initialize triggered Samples Manager. It simply removes all data from the related Azure Table Storage table.
PrepareCodeFragments is an Azure Function responsible for loading and parsing data from specified blob.
CodeSampleManager is an Azure Function responsible for managing content items of Code Sample type in Kentico Kontent. It prepares objects of data and passes it to the Kentico Kontent.
CodeSamplesManager is an Azure Function responsible for managing content items of Code Samples type in Kentico Kontent. Function is also responsible for managing table in Azure Table Storage. In this table, function stores information about already processed code samples together with its status (active/archived). Current table entity consists of:
-
Partition Key
- is represented by the codename of the code samples content item -
Row Key
- is represented by the codename of the code sample content item -
Timestamp
- auto-generated timestamp -
Status
- either active or archived - used for archiving code samples items
Function creates new code samples item and take care of correct linking of related code sample items if 2 or more related code sample items are already stored in Kentico Kontent. Next responsibility is to add linked item if new related item was created by CodeSampleManager. Function archives code samples item if all code sample items linked in the specified item are marked as archived in the related table.
For further information about Orchestrator and Starter function, please read through official documentation of Azure Durable Functions.
After the successful run of Samples Manager the content between GitHub repository and Kentico Kontent project should be synchronized and ready to use in other content types of the project.
- Overview
- Website
- Dispatcher
- Notifier
- Search Functionality
- GitHub Integration
- Bulk Publishing / Scheduling to Publish
- API Reference
- Integration Tests
- Content Models