Skip to content

Commit 85e13e4

Browse files
authored
Merge pull request buerokratt#929 from 1AhmedYasser/fix-blob-storage-update
Fix: Blob Storage Update on Status Change From Active
2 parents 49aba9f + bb43961 commit 85e13e4

3 files changed

Lines changed: 102 additions & 5 deletions

File tree

‎DSL/Ruuter/services/POST/services/edit.yml‎

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,59 @@ service_edit:
229229
check for_state:
230230
switch:
231231
- condition: ${state === 'draft'}
232-
next: change_state_to_draft
232+
next: check_remove_blob_then_draft
233233
- condition: ${state === 'active'}
234234
next: check_if_service_data_exists
235+
next: check_remove_blob_then_ok
236+
237+
check_remove_blob_then_draft:
238+
switch:
239+
- condition: ${old_state === 'active'}
240+
next: delete_from_storage_edit
241+
next: change_state_to_draft
242+
243+
check_remove_blob_then_ok:
244+
switch:
245+
- condition: ${old_state === 'active'}
246+
next: delete_from_storage_edit
247+
next: return_ok
248+
249+
delete_from_storage_edit:
250+
call: http.delete
251+
args:
252+
url: "[#STORAGE_FERRY]/v1/files/delete"
253+
body:
254+
files:
255+
- storageAccountId: "[#STORAGE_FERRY_ACCOUNT_ID]"
256+
container: "[#STORAGE_FERRY_CONTAINER]"
257+
fileName: "${old_name}.json"
258+
result: ferry_delete_result
259+
next: check_if_azure_configured_after_delete_edit
260+
261+
check_if_azure_configured_after_delete_edit:
262+
switch:
263+
- condition: ${"[#AZURE_SEARCH_SERVICE_NAME]" !== "" && "[#AZURE_SEARCH_INDEXER_NAME]" !== "" && "[#AZURE_SEARCH_API_KEY]" !== ""}
264+
next: trigger_azure_indexer_after_delete_edit
265+
next: log_azure_not_configured_after_delete_edit
266+
267+
log_azure_not_configured_after_delete_edit:
268+
log: "Warning! Azure Search configuration not found. Skipping Azure indexer trigger. Please configure AZURE_SEARCH_SERVICE_NAME, AZURE_SEARCH_INDEXER_NAME, and AZURE_SEARCH_API_KEY in constants.ini"
269+
next: after_delete_from_storage_edit
270+
271+
trigger_azure_indexer_after_delete_edit:
272+
call: http.post
273+
args:
274+
url: "https://[#AZURE_SEARCH_SERVICE_NAME].search.windows.net/indexers/[#AZURE_SEARCH_INDEXER_NAME]/run?api-version=2024-07-01"
275+
headers:
276+
api-key: "[#AZURE_SEARCH_API_KEY]"
277+
Content-Type: "application/json"
278+
result: azure_indexer_result
279+
next: after_delete_from_storage_edit
280+
281+
after_delete_from_storage_edit:
282+
switch:
283+
- condition: ${state === 'draft'}
284+
next: change_state_to_draft
235285
next: return_ok
236286

237287
change_state_to_draft:

‎DSL/Ruuter/services/POST/services/status.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ deactivate_service:
206206
next: delete_from_storage
207207

208208
delete_from_storage:
209-
call: http.post
209+
call: http.delete
210210
args:
211211
url: "[#STORAGE_FERRY]/v1/files/delete"
212212
body:

‎docs/INTENT_CLASSIFICATION.MD‎

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ Intent files are published to Azure Blob Storage and indexed for LLM-based inten
2121

2222
**In `edit.yml`:**
2323

24-
- Blob storage operations occur **only when the service state is being set to 'active'**
25-
- When a service is edited and the state is set to 'active', the intent file (JSON format) is uploaded or updated in Azure Blob Storage using Storage Ferry
24+
- When a service is edited and the state is set to **'active'**, the intent file (JSON format) is uploaded or updated in Azure Blob Storage using Storage Ferry
25+
- When a service is edited and the state is changed **from active to draft or ready** (or any other non-active status), the intent file is deleted from blob storage
2626
- The file is stored with the service name as the filename (e.g., `service-name.json`)
2727

2828
**In `status.yml`:**
2929

3030
- When a service is **activated** (state changed to 'active'): the intent file is created in blob storage
31-
- When a service is **deactivated** (state changed to inactive): the intent file is deleted from blob storage
31+
- When a service changes **from active to any other status** (e.g. inactive or draft): the intent file is deleted from blob storage
3232

3333
**Blob storage operations:**
3434

@@ -264,3 +264,50 @@ Currently, we had low test sample size during development making testing results
264264
### Follow-up note.
265265

266266
As in its current iteration we have only basic MVP version, some aspects of this procedure are still raw and inconsistent, and with its development this document should be updated accordingly.
267+
268+
269+
## 9. Local Development Notes
270+
271+
#### To Access Azrite in Terminal
272+
273+
- Install az cli
274+
- To view blob list in a container
275+
```
276+
az storage blob list --container-name {CONTAINER_NAME} --connection-string "DefaultEndpointsProtocol=http;AccountName={ACCOUNT_NAME};AccountKey={ACCOUNT_KEY};BlobEndpoint={ENDPOINT}" --auth-mode key --output table
277+
```
278+
- To View blob json content
279+
```
280+
view_blob_temp() {
281+
local container=$1
282+
local blob=$2
283+
local temp_file="./temp_$blob"
284+
285+
# Download
286+
echo "📥 Downloading $blob..."
287+
az storage blob download --container-name "$container" --name "$blob" --file "$temp_file" --connection-string "DefaultEndpointsProtocol=http;AccountName={ACCOUNT_NAME};AccountKey={ACCOUNT_KEY};BlobEndpoint={ENDPOINT}" --auth-mode key
288+
289+
# View
290+
echo -e "\n📄 Contents:"
291+
cat "$temp_file"
292+
293+
# Ask to keep or remove
294+
echo -e "\n\nDelete temporary file? (y/n)"
295+
read answer
296+
if [ "$answer" = "y" ]; then
297+
rm "$temp_file"
298+
echo "🗑️ Temporary file removed"
299+
else
300+
echo "💾 File saved as: $temp_file"
301+
fi
302+
}
303+
304+
# Usage
305+
view_blob_temp {CONTAINER_NAME} "{NAME}.json"
306+
```
307+
- To delete blobs list
308+
```
309+
az storage blob list --container-name buerokratt --query "[].name" --output tsv --connection-string "DefaultEndpointsProtocol=http;AccountName={ACCOUNT_NAME};AccountKey={ACCOUNT_KEY};BlobEndpoint={ENDPOINT}" --auth-mode key | while read blob; do
310+
echo "Deleting $blob..."
311+
az storage blob delete --container-name buerokratt --name "$blob" --connection-string "DefaultEndpointsProtocol=http;AccountName={ACCOUNT_NAME};AccountKey={ACCOUNT_KEY};BlobEndpoint={ENDPOINT}" --auth-mode key
312+
done
313+
```

0 commit comments

Comments
 (0)