---
# System prepended metadata

title: Recap

---

# Recap
1. CR
    - 錄影時間
    - 錄影檔保存時間
2. Merge CR
    - 指定 start/end time
    - merge CR 檔案 -> 快轉 -> 上傳
    - for VIP (小樹屋) 客戶

## Issue
1. 調整 merge CR 過期時間
```
    function getRemoveTimestamp($request) {
        // 30 days after start time
        return MergeCRHistoryModel::getDefaultExpiredTime($request);
    }
```
2. 調整 merge cr 刪除 DB 邏輯 (MergeCRModel::archiveBatchRequests)
3. 部分 Merge CR 檔案沒有刪除 (中間改版過，資料格式有變動, 導致早期檔案沒有刪除)

# Merge CR
## 進入點
service_backend/service_backend_api/backend_service/MergeCR/do_merge_cr.php

## Flow
- 呼叫 frontend API -> trigger 後端 merge cr service
- merge cr service -> 產生檔案 + 更新 DB
- https://docs.google.com/document/d/1zcu2swhL4AEeSaHuT8UCJkwO6AlngYfWHlZYksqktuI/edit

## Test In Sandbox
```
cd test/00_epic_test/
sudo tox -r -e py36
/tmp/sandbox/.tox/py36/bin/pytest api/test_merge_cr.py 
```

# File Deletion

## 進入點
dealer_api/script/file_deletion/run_producer.php
```
0 2,10,18 * * * nice php /home/ubuntu/dealer_api/script/file_deletion/run_producer.php
```

## 刪除種類
1. archive (CR/ER)
2. merge cr
3. snapshot

## Flow
1. 產生需要處理的時間區間 (run_producer.php)
2. 根據時間區間找出需要刪除的 task, 待處理的放入 cache (redis) (producer.php)
3. 去 S3/AWS 刪除檔案 (consumer.php) + 通知 frontend 刪除 DB 資料

![](https://i.imgur.com/g3dh71O.png)


## Log
```
/tmp/physically_remove_archive_files/
```

## Handler
### Interface
```
interface IMessageHandler {
    const CHUNK_MAX_SIZE = 50;
    const REGION_DELIMITER = '::::';
    const FILEID_DELIMITER = ':::';
    function getFilesToDelete($db, $start_time, $end_time, $time_to_delete, $logger);
    function removeFilesIfExistInCache($files, $exist_id_map, $logger);
    function groupFilesByRegion($db, $files);
    function notifyRemoveFiles($id_list, $logger);
    function getEncodedRemoveFileId($file);
}

```

```
1. dealer_api/script/file_deletion/handler/ArchiveMessageHandler.php
2. dealer_api/script/file_deletion/handler/MergeCRMessageHandler.php
3. dealer_api/script/file_deletion/handler/SnapshotMessageHandler.php
```

## Test in Sandbox
```
cd test/00_epic_test/
sudo tox -r -e py36
/tmp/sandbox/.tox/py36/bin/pytest  file_deletion/test_server.py
```