优化代码,增加存储迁移锁解除功能

dependabot/npm_and_yarn/fir_admin/eventsource-1.1.1
nineven 3 years ago
parent c36ab08f35
commit b191cbae6b
  1. 51
      fir_client/src/components/user/FirUserStorage.vue
  2. 8
      fir_client/src/utils/index.js
  3. 3
      fir_ser/api/utils/modelutils.py
  4. 5
      fir_ser/api/utils/utils.py
  5. 11
      fir_ser/api/views/storage.py
  6. 3
      fir_ser/common/cache/state.py

@ -669,8 +669,6 @@
<el-tag style="margin: 20px 0"> 应用版本数设置当应用历史版本超过该限制将会自动清理较老的版本</el-tag> <el-tag style="margin: 20px 0"> 应用版本数设置当应用历史版本超过该限制将会自动清理较老的版本</el-tag>
<div style="margin: auto;width: 700px;height: 100%"> <div style="margin: auto;width: 700px;height: 100%">
<el-form ref="form" :model="storage_config" label-width="180px"> <el-form ref="form" :model="storage_config" label-width="180px">
<el-form-item label="应用历史版本数" style="text-align: left"> <el-form-item label="应用历史版本数" style="text-align: left">
<el-input-number v-model="storage_config.user_history_limit" :min="1" <el-input-number v-model="storage_config.user_history_limit" :min="1"
style="width: 300px;margin: 0 10px"></el-input-number> style="width: 300px;margin: 0 10px"></el-input-number>
@ -685,6 +683,18 @@
{{ diskSize(storage_config.user_max_storage_capacity - storage_config.user_used_storage_capacity) }} {{ diskSize(storage_config.user_max_storage_capacity - storage_config.user_used_storage_capacity) }}
</el-tag> </el-tag>
</el-form-item> </el-form-item>
<el-form-item label="存储迁移状态" style="text-align: left">
<el-tag v-if="!storage_config.storage_status">未迁移状态正常</el-tag>
<div v-else>
<el-tag>迁移中迁移时间 {{ getFormatDate(storage_config.storage_status) }}</el-tag>
<el-tag type="warning">若存储状态长时间处于迁移中可能是迁移卡死了可以尝试
<el-button plain size="mini" type="text" @click="cancelStorage">解除迁移锁</el-button>
进行解除
</el-tag>
</div>
</el-form-item>
<el-form-item label="清理所有应用数据" style="text-align: left"> <el-form-item label="清理所有应用数据" style="text-align: left">
<el-button style="margin-left: 10px" <el-button style="margin-left: 10px"
type="danger" type="danger"
@ -692,7 +702,6 @@
清理所有应用数据 清理所有应用数据
</el-button> </el-button>
</el-form-item> </el-form-item>
<el-form-item label="清理应用历史数据" style="text-align: left"> <el-form-item label="清理应用历史数据" style="text-align: left">
<el-button style="margin-left: 10px" <el-button style="margin-left: 10px"
type="danger" type="danger"
@ -700,7 +709,6 @@
清理应用历史版本数据只保留最新版本数据 清理应用历史版本数据只保留最新版本数据
</el-button> </el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
</div> </div>
@ -724,7 +732,7 @@
<script> <script>
import {cleanStorageData, configStorageData, getStorageinfo, shareStorageData} from "@/restful"; import {cleanStorageData, configStorageData, getStorageinfo, shareStorageData} from "@/restful";
import {deepCopy, diskSize, getUserInfoFun} from "@/utils"; import {deepCopy, diskSize, getFormatDate, getUserInfoFun} from "@/utils";
import {format_time} from "@/utils/base/utils"; import {format_time} from "@/utils/base/utils";
export default { export default {
@ -734,7 +742,12 @@ export default {
pagination: {"currentPage": 1, "total": 0, "pagesize": 10}, pagination: {"currentPage": 1, "total": 0, "pagesize": 10},
target_uid: '', target_uid: '',
shareInfo: '', shareInfo: '',
storage_config: {'user_history_limit': 0, 'user_max_storage_capacity': 0, 'user_used_storage_capacity': 0}, storage_config: {
'user_history_limit': 0,
'user_max_storage_capacity': 0,
'user_used_storage_capacity': 0,
'storage_status': 0
},
target_number: '', target_number: '',
fstorage_lists: [], fstorage_lists: [],
share_bill_lists: [], share_bill_lists: [],
@ -765,6 +778,29 @@ export default {
}, methods: { }, methods: {
format_time, format_time,
diskSize, diskSize,
getFormatDate,
cancelStorage() {
this.$confirm("确定要解除迁移锁么,在未完成迁移状态下解除迁移锁之后,可能会导致数据异常?", '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
configStorageData(res => {
if (res.code === 1000) {
this.$message.success("操作成功")
this.refreshactiveFun()
} else {
this.$message.error("操作失败了," + res.msg)
}
}, {"methods": "POST", "data": this.storage_config})
}).catch(() => {
this.$message({
type: 'info',
message: '已取消撤回操作'
});
});
},
storage_usedColor(percentage) { storage_usedColor(percentage) {
if (percentage < 20) { if (percentage < 20) {
return '#6f7ad3'; return '#6f7ad3';
@ -792,7 +828,7 @@ export default {
loading.close() loading.close()
if (res.code === 1000) { if (res.code === 1000) {
this.$message.success("操作成功") this.$message.success("操作成功")
this.storage_config = res.data this.refreshactiveFun()
} else { } else {
this.$message.error("操作失败了," + res.msg) this.$message.error("操作失败了," + res.msg)
} }
@ -1048,6 +1084,7 @@ export default {
loading.close(); loading.close();
if (data.code === 1000) { if (data.code === 1000) {
this.$message.success('清理成功'); this.$message.success('清理成功');
this.refreshactiveFun();
} else { } else {
this.$message.error(data.msg) this.$message.error(data.msg)
} }

@ -662,3 +662,11 @@ export function format_choices(key, obj) {
} }
return "未知" return "未知"
} }
export function getFormatDate(timestamp) {
let now = new Date(timestamp * 1000)
let y = now.getFullYear()
let m = now.getMonth() + 1
let d = now.getDate()
return y + "-" + (m < 10 ? "0" + m : m) + "-" + (d < 10 ? "0" + d : d) + " " + now.toTimeString().substr(0, 8);
}

@ -126,7 +126,8 @@ def base_random_weight(obj, key):
def ad_random_weight(user_obj): def ad_random_weight(user_obj):
ad_info_list = UserAdDisplayInfo.objects.filter(user_id=user_obj, is_enable=True).order_by('-created_time') ad_info_list = UserAdDisplayInfo.objects.filter(user_id=user_obj, is_enable=True, ad_pic__regex='.+').order_by(
'-created_time')
return base_random_weight(ad_info_list, 'weight') return base_random_weight(ad_info_list, 'weight')

@ -77,8 +77,9 @@ def change_storage_and_change_head_img(user_obj, new_storage_obj, clean_old_data
def change_storage_and_change_advert_img(user_obj, new_storage_obj, clean_old_data=True): def change_storage_and_change_advert_img(user_obj, new_storage_obj, clean_old_data=True):
for user_advert_obj in UserAdDisplayInfo.objects.filter(user_id=user_obj): for user_advert_obj in UserAdDisplayInfo.objects.filter(user_id=user_obj, ad_pic__regex='.+'):
migrating_storage_file_data(user_obj, user_advert_obj.ad_pic, new_storage_obj, clean_old_data) if len(user_advert_obj.ad_pic) > 5:
migrating_storage_file_data(user_obj, user_advert_obj.ad_pic, new_storage_obj, clean_old_data)
def download_files_form_oss(storage_obj, org_file, force=False): def download_files_form_oss(storage_obj, org_file, force=False):

@ -422,10 +422,12 @@ class StorageConfigView(APIView):
'user_max_storage_capacity': get_user_storage_capacity(request.user), 'user_max_storage_capacity': get_user_storage_capacity(request.user),
'user_used_storage_capacity': get_user_storage_used(request.user), 'user_used_storage_capacity': get_user_storage_used(request.user),
'user_history_limit': UserInfo.objects.filter(pk=request.user.pk).first().history_release_limit, 'user_history_limit': UserInfo.objects.filter(pk=request.user.pk).first().history_release_limit,
'storage_status': MigrateStorageState(request.user.uid).get_state()
} }
return Response(res.dict) return Response(res.dict)
def put(self, request): def put(self, request):
res = BaseResponse()
history_release_limit = request.data.get('user_history_limit') history_release_limit = request.data.get('user_history_limit')
if history_release_limit: if history_release_limit:
try: try:
@ -440,4 +442,11 @@ class StorageConfigView(APIView):
for app_obj in app_obj_lists: for app_obj in app_obj_lists:
clean_history_apps(app_obj, request.user, abs(history_release_limit)) clean_history_apps(app_obj, request.user, abs(history_release_limit))
return self.get(request) return Response(res.dict)
def post(self, request):
res = BaseResponse()
migrate_obj = MigrateStorageState(request.user.uid)
if migrate_obj.get_state() == request.data.get('storage_status'):
migrate_obj.del_state()
return Response(res.dict)

@ -22,6 +22,9 @@ class CacheBaseState(object):
def get_state(self): def get_state(self):
return cache.get(self.key) return cache.get(self.key)
def del_state(self):
return cache.delete(self.key)
def __enter__(self): def __enter__(self):
if cache.get(self.key): if cache.get(self.key):
return False return False

Loading…
Cancel
Save