Skip to content

Let's use AI to Earn!

feat: 自动任务添加立即执行

yikaJasonMic1826dd7d3dfa
diff --git a/electron/main/autoRun/controller.ts b/electron/main/autoRun/controller.ts
index 23f591ed..67d4b1f6 100644
--- a/electron/main/autoRun/controller.ts
+++ b/electron/main/autoRun/controller.ts
@@ -1,7 +1,7 @@
/*
* @Author: nevin
* @Date: 2025-01-20 22:02:54
- * @LastEditTime: 2025-03-23 18:34:36
+ * @LastEditTime: 2025-03-28 13:33:08
* @LastEditors: nevin
* @Description: autoRun AutoRun
*/
@@ -135,6 +135,19 @@ export class AutoRunController {
return list;
}
+ // 立即执行进程
+ @Icp('ICP_RUN_NOW_AUTO_RUN')
+ async autoRunStart(event: Electron.IpcMainInvokeEvent, id: number) {
+ const item = await this.autoRunService.findAutoRunById(id);
+ if (!item) return false;
+
+ const tag = autoRunTypeEtTag.get(item.type);
+ if (!tag) return false;
+
+ EtEvent.emit(tag, item);
+ return true;
+ }
+
// 每5分钟进行一次自动启动
@Scheduled('*/1 * * * *', 'all_auto_run_start')
async syncAllAutoRunStart() {
diff --git a/electron/main/autoRun/service.ts b/electron/main/autoRun/service.ts
index d5591176..7d6d2e37 100644
--- a/electron/main/autoRun/service.ts
+++ b/electron/main/autoRun/service.ts
@@ -14,7 +14,7 @@ import {
AutoRunRecordModel,
AutoRunRecordStatus,
} from '../../db/models/autoRunRecord';
-import { FindOptionsWhere, Repository } from 'typeorm';
+import { FindOptionsWhere, Not, Repository } from 'typeorm';
import { AppDataSource } from '../../db';
import windowOperate from '../../util/windowOperate';
import { SendChannelEnum } from '../../../commont/UtilsEnum';
@@ -79,6 +79,7 @@ export class AutoRunService {
}> {
const { page, pageSize } = pageInfo;
const whereClause: FindOptionsWhere<AutoRunModel> = {
+ status: Not(AutoRunStatus.DELETE),
...(query.type !== undefined && { type: query.type }),
...(query.status !== undefined && { status: query.status }),
...(query.cycleType !== undefined && { cycleType: query.cycleType }),
diff --git a/src/icp/autoRun.ts b/src/icp/autoRun.ts
index 8a04f76c..77778f13 100644
--- a/src/icp/autoRun.ts
+++ b/src/icp/autoRun.ts
@@ -1,7 +1,7 @@
/*
* @Author: nevin
* @Date: 2025-01-23 15:48:14
- * @LastEditTime: 2025-03-23 11:49:28
+ * @LastEditTime: 2025-03-28 13:35:19
* @LastEditors: nevin
* @Description: 自动进程
*/
@@ -145,3 +145,15 @@ export async function ipcCreateAutoRunRecord(autoRunId: number) {
);
return res;
}
+
+/**
+ * 立即执行进程
+ * @param id
+ */
+export async function ipcRunNowAutoRun(id: number) {
+ const res: boolean = await window.ipcRenderer.invoke(
+ 'ICP_RUN_NOW_AUTO_RUN',
+ id,
+ );
+ return res;
+}
diff --git a/src/views/reply/autoRun.tsx b/src/views/reply/autoRun.tsx
index 93b45aaa..a2d3b4f5 100644
--- a/src/views/reply/autoRun.tsx
+++ b/src/views/reply/autoRun.tsx
@@ -3,11 +3,13 @@ import {
AutoRunStatus,
AutoRunType,
ipcGetAutoRunList,
+ ipcRunNowAutoRun,
ipcUpdateAutoRunStatus,
} from '@/icp/autoRun';
-import { Popconfirm, Space, Table } from 'antd';
+import { Button, Popconfirm, Space, Table } from 'antd';
import React from 'react';
import AutoRunRecord, { AutoRunRecordRef } from './components/autoRunRecord';
+import { ParseCronSchedule } from '@/components/CronSchedule';
const { Column } = Table;
@@ -56,8 +58,35 @@ const Page: React.FC = () => {
getAutoRunList();
}, [pagination.page, pagination.pageSize]);
+ // 添加刷新功能的函数
+ function refreshAutoRunList() {
+ getAutoRunList();
+ }
+
+ function runNowAutoRun(data: AutoRun) {
+ ipcRunNowAutoRun(data.id);
+ }
+
+ // 添加状态映射
+ const statusMap: { [key in AutoRunStatus]: string } = {
+ [AutoRunStatus.DOING]: '活跃',
+ [AutoRunStatus.PAUSE]: '暂停',
+ [AutoRunStatus.DELETE]: '删除',
+ // 可以根据需要添加更多状态
+ };
+
+ // 添加类型映射
+ const typeMap: { [key in AutoRunType]: string } = {
+ [AutoRunType.ReplyComment]: '回复评论',
+ // 可以根据需要添加更多类型
+ };
+
return (
<div style={{ width: '100%' }} className="bg-slate-500">
+ {/* 添加刷新按钮 */}
+ <Button onClick={refreshAutoRunList} style={{ marginBottom: 16 }}>
+ 刷新
+ </Button>
<Table
rowKey="id"
dataSource={autoRunList}
@@ -76,9 +105,26 @@ const Page: React.FC = () => {
<Column title="用户DI" dataIndex="userId" key="userId" />
<Column title="账户ID" dataIndex="accountId" key="accountId" />
<Column title="运行次数" dataIndex="runCount" key="runCount" />
- <Column title="状态" dataIndex="status" key="status" />
- <Column title="类型" dataIndex="type" key="type" />
- <Column title="触发周期" dataIndex="cycleType" key="cycleType" />
+ <Column
+ title="状态"
+ dataIndex="status"
+ key="status"
+ render={(status: AutoRunStatus) => statusMap[status]}
+ />
+ <Column
+ title="类型"
+ dataIndex="type"
+ key="type"
+ render={(type: AutoRunType) => typeMap[type]}
+ />
+ <Column
+ title="触发周期"
+ dataIndex="cycleType"
+ key="cycleType"
+ render={(cycleType: string) => (
+ <ParseCronSchedule cronExpression={cycleType} />
+ )}
+ />
<Column
title="创建时间"
key="createTime"
@@ -113,13 +159,12 @@ const Page: React.FC = () => {
>
<a>删除</a>
</Popconfirm>
-
+ <a onClick={() => runNowAutoRun(record)}>立即执行</a>
<a onClick={() => openAutoRunRecord(record)}>打开记录</a>
</Space>
)}
/>
</Table>
-
<AutoRunRecord ref={Ref_AutoRunRecord} />
</div>
);