Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Commit

Permalink
Add retry functionality for failed train and publish jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
niostack committed Feb 14, 2024
1 parent 020dba2 commit d57f43e
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 61 deletions.
2 changes: 2 additions & 0 deletions src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const api = {
count_online_device: '/api/device/count_online',
count_all_account: '/api/account/count_all',
count_account_by_group_id: '/api/account/count_by_group_id',
retry_all_failed_train_job: '/api/train_job/retry_all',
retry_all_failed_publish_job: '/api/publish_job/retry_all',

}
export default api
130 changes: 82 additions & 48 deletions src/components/dashboard/ManageDashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@
<div class="flex flex-col items-start p-12 w-full">

<h1 class="text-2xl mb-6">{{ $t('dashboard') }}</h1>
<div class="divider">{{ $t('quickStart') }}</div>
<ul class="steps">
<li class="step step-primary">{{ $t('step.step1') }}</li>
<li class="step step-primary">{{ $t('step.step2') }}</li>
<li class="step step-primary">{{ $t('step.step3') }}</li>
<li class="step step-primary">{{ $t('step.step4') }}</li>
<li class="step step-primary">{{ $t('step.step5') }}</li>
<li class="step step-primary">{{ $t('step.step6') }}</li>
<li class="step step-primary">{{ $t('step.step7') }}</li>
</ul>
<div tabindex="0" class="collapse collapse-arrow border border-base-300 bg-base-200">
<div class="collapse-title text-xl font-medium">
{{ $t('quickStart') }}
</div>
<div class="collapse-content">
<ul class="steps">
<li class="step step-primary">{{ $t('step.step1') }}</li>
<li class="step step-primary">{{ $t('step.step2') }}</li>
<li class="step step-primary">{{ $t('step.step3') }}</li>
<li class="step step-primary">{{ $t('step.step4') }}</li>
<li class="step step-primary">{{ $t('step.step5') }}</li>
<li class="step step-primary">{{ $t('step.step6') }}</li>
<li class="step step-primary">{{ $t('step.step7') }}</li>
</ul>
</div>
</div>

<div class="divider">{{ $t('overview') }}</div>
<div class="stats shadow">
<div class="stat">
Expand Down Expand Up @@ -66,41 +73,21 @@
</div>
</div>
<div class="divider">{{ $t('matrixGroup') }}</div>
<div class="stats bg-primary text-primary-content carousel carousel-center rounded-box w-full">
<div class="stat carousel-item">
<div class="stat-value">Matrix Group A</div>
<div class="stat-actions">
<button class="btn btn-sm btn-success">Videos:99</button>
<button class="btn btn-sm btn-info ml-2">Accounts:100</button>

</div>
</div>
<div class="divider lg:divider-horizontal"></div>
<div class="stat carousel-item">
<div class="stat-value">Matrix Group B</div>
<div class="stat-actions">
<button class="btn btn-sm btn-success">Videos:99</button>
<button class="btn btn-sm btn-info ml-2">Accounts:100</button>
</div>
</div>
<div class="divider lg:divider-horizontal"></div>
<div class="stat carousel-item">
<div class="stat-value">Matrix Group C</div>
<div class="stat-actions">
<button class="btn btn-sm btn-success">Videos:99</button>
<button class="btn btn-sm btn-info ml-2">Accounts:100</button>
</div>
</div>
<div class="divider lg:divider-horizontal"></div>
<div class="stat carousel-item">
<div class="stat-value">Matrix Group D</div>
<div class="stat-actions">
<button class="btn btn-sm btn-success">Videos:99</button>
<button class="btn btn-sm btn-info ml-2">Accounts:100</button>
<div class="stats bg-primary text-primary-content carousel carousel-center rounded-box max-w-full">
<div v-for="group in groups" :key="group.id">
<div class="stat carousel-item">
<div class="stat-value">{{ group.name }}</div>
<div class="stat-title text-primary-content">{{ $t('accountCount') }}: {{ group.account_count }}</div>
<div class="stat-actions">
<button class="btn btn-sm btn-success" @click="addMaterial(group)">{{ $t('addMaterial') }}:{{
group.unused_material_count }}</button>
</div>
</div>
<div class="divider lg:divider-horizontal"></div>
</div>
</div>
</div>
<input id="upload_material_input" type="file" v-on:change="on_upload_material" multiple hidden>
</template>
<script>
import Button from '../Button.vue'
Expand All @@ -122,7 +109,8 @@ export default {
running_publish_job_count: 0,
train_job_queue: 0,
publish_job_queue: 0,
groups: []
groups: [],
currentGroup: null,
}
},
methods: {
Expand All @@ -143,8 +131,11 @@ export default {
count_train_job_by_status() {
this.$service.count_train_job_by_status().then(res => {
const status_count_list = res.data;
const { all_count, success_count, queue_count, running_count } = status_count_list.reduce((acc, item) => {
const { all_count, success_count, failed_count, queue_count, running_count } = status_count_list.reduce((acc, item) => {
acc.all_count += item.count;
if (item.status === 3) {
acc.failed_count = item.count;
}
if (item.status === 2) {
acc.success_count = item.count;
}
Expand All @@ -155,10 +146,10 @@ export default {
acc.queue_count = item.count;
}
return acc;
}, { all_count: 0, success_count: 0, queue_count: 0 });
}, { all_count: 0, success_count: 0, failed_count: 0, queue_count: 0, running_count: 0 });
this.train_job_count = all_count;
this.train_job_sucess_rate = (success_count / all_count).toFixed(4);
this.train_job_sucess_rate = (1 - failed_count / all_count).toFixed(4);
this.train_job_queue = queue_count;
this.running_train_job_count = running_count;
}).catch(err => {
Expand All @@ -168,8 +159,11 @@ export default {
count_publish_job_by_status() {
this.$service.count_publish_job_by_status().then(res => {
const status_count_list = res.data;
const { all_count, success_count, queue_count, running_count } = status_count_list.reduce((acc, item) => {
const { all_count, success_count, failed_count, queue_count, running_count } = status_count_list.reduce((acc, item) => {
acc.all_count += item.count;
if (item.status === 3) {
acc.failed_count = item.count;
}
if (item.status === 2) {
acc.success_count = item.count;
}
Expand All @@ -180,10 +174,10 @@ export default {
acc.queue_count = item.count;
}
return acc;
}, { all_count: 0, success_count: 0, queue_count: 0 });
}, { all_count: 0, success_count: 0, failed_count: 0, queue_count: 0, running_count: 0 });
this.publish_job_count = all_count;
this.publish_job_sucess_rate = (success_count / all_count).toFixed(4);
this.publish_job_sucess_rate = (1 - failed_count / all_count).toFixed(4);
this.publish_job_queue = queue_count;
this.running_publish_job_count = running_count;
}).catch(err => {
Expand All @@ -193,6 +187,46 @@ export default {
get_groups() {
this.$service.get_groups().then(res => {
this.groups = res.data
for (let i = 0; i < this.groups.length; i++) {
this.get_unused_material_count(this.groups[i])
this.count_account_by_group_id(this.groups[i])
}
}).catch(err => {
console.log(err)
})
},
get_unused_material_count(group) {
this.$service.get_material_count({
group_id: group.id,
used: 0
}).then(res => {
group.unused_material_count = res.data
}).catch(err => {
console.log(err)
})
},
count_account_by_group_id(group) {
this.$service.count_account_by_group_id({
group_id: group.id
}).then(res => {
group.account_count = res.data
}).catch(err => {
console.log(err)
})
},
addMaterial(group) {
this.currentGroup = group
document.getElementById('upload_material_input').click()
},
on_upload_material(e) {
const formData = new FormData()
formData.append('group_id', this.currentGroup.id)
for (let i = 0; i < e.target.files.length; i++) {
formData.append('files', e.target.files[i])
}
this.$service.upload_material(formData).then(res => {
console.log(res)
this.get_unused_material_count(this.currentGroup)
}).catch(err => {
console.log(err)
})
Expand Down
9 changes: 8 additions & 1 deletion src/components/publishJob/ManagePublishJobs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="w-full">
<Pagination :items="jobs" :pageSize="10" :searchKeys="['device', 'id', 'account']" @refresh="get_publish_jobs">
<template v-slot:buttons>
<!-- <Button @click="create_job" label="add" /> -->
<Button @click="retry_all_failed" label="retryAllFaied" />
</template>
<template v-slot:default="slotProps">
<div class="overflow-x-auto">
Expand Down Expand Up @@ -154,6 +154,13 @@ export default {
console.log(err)
})
},
retry_all_failed() {
this.$service.retry_all_failed_publish_job().then(res => {
this.get_publish_jobs()
}).catch(err => {
console.log(err)
})
}
},
mounted() {
this.get_publish_jobs();
Expand Down
9 changes: 8 additions & 1 deletion src/components/trainJob/ManageTrainJobs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="w-full">
<Pagination :items="jobs" :pageSize="10" :searchKeys="['device', 'id', 'account']" @refresh="get_train_jobs">
<template v-slot:buttons>
<!-- <Button @click="create_job" label="add" /> -->
<Button @click="retry_all_failed" label="retryAllFaied" />
</template>
<template v-slot:default="slotProps">
<div class="overflow-x-auto">
Expand Down Expand Up @@ -130,6 +130,13 @@ export default {
console.log(err)
})
},
retry_all_failed() {
this.$service.retry_all_failed_train_job().then(res => {
this.get_train_jobs()
}).catch(err => {
console.log(err)
})
}
},
mounted() {
this.get_train_jobs()
Expand Down
22 changes: 12 additions & 10 deletions src/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ export const i18n = createI18n({
dashboard: 'Dashboard',
allGroups: 'All Groups',
step: {
step1: 'Download TikTok Matrix',
step2: 'Open TikTok Matrix',
step3: 'Create Matrix Group',
step4: 'Config Matrix Group',
step5: 'Auto Register Accounts',
step1: 'Download/Install',
step2: 'Open Server&Agent',
step3: 'Create Group',
step4: 'Add Settings',
step5: 'Auto Register',
step6: 'Auto Train',
step7: 'Auto Publish',
},
Expand All @@ -143,6 +143,7 @@ export const i18n = createI18n({
trainJobQueue: 'TrainJob Queue',
publishJobQueue: 'PublishJob Queue',
matrixGroup: 'Matrix Group',
accountCount: 'Account Count',
},
'zh-CN': {
siteName: 'TikTok 矩阵',
Expand Down Expand Up @@ -267,11 +268,11 @@ export const i18n = createI18n({
dashboard: '仪表盘',
allGroups: '全部分组',
step: {
step1: '下载 TikTok 矩阵',
step2: '打开 TikTok 矩阵',
step3: '创建矩阵分组',
step4: '配置矩阵分组',
step5: '自动注册帐号',
step1: '下载/安装',
step2: '打开Server&Agent',
step3: '创建分组',
step4: '添加设置',
step5: '自动注册',
step6: '自动养号',
step7: '自动发布',
},
Expand All @@ -284,6 +285,7 @@ export const i18n = createI18n({
trainJobQueue: '养号任务队列',
publishJobQueue: '发布任务队列',
matrixGroup: '矩阵分组',
accountCount: '帐号数量',

}
}
Expand Down
3 changes: 2 additions & 1 deletion src/mock/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ const data = {
"status": 3,
"count": 232,
},
]
],
[api.count_account_by_group_id]: Math.floor(Math.random() * 100),
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,18 @@ export function count_account_by_group_id({ group_id }) {
params: { group_id }
})
}
export function retry_all_failed_train_job() {
return request({
method: 'get',
url: api.retry_all_failed_train_job,
})
}
export function retry_all_failed_publish_job() {
return request({
method: 'get',
url: api.retry_all_failed_publish_job,
})
}



0 comments on commit d57f43e

Please sign in to comment.