Skip to content

Commit

Permalink
feat: ui to manaul trigger cron jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-ding committed Sep 7, 2024
1 parent 5923fc7 commit bf608f9
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 5 deletions.
12 changes: 12 additions & 0 deletions ui/lib/providers/APIs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class APIs {

static final tmdbImgBaseUrl = "$_baseUrl/api/v1/posters";

static final cronJobUrl = "$_baseUrl/api/v1/setting/cron/trigger";

static const tmdbApiKey = "tmdb_api_key";
static const downloadDirKey = "download_dir";

Expand Down Expand Up @@ -100,4 +102,14 @@ class APIs {
context.go('/login');
}
}

static Future<void> triggerCronJob(String name) async {
var resp = await getDio().post(APIs.cronJobUrl, data: {"job_name": name});

var sp = ServerResponse.fromJson(resp.data);

if (sp.code != 0) {
throw sp.message;
}
}
}
62 changes: 59 additions & 3 deletions ui/lib/system_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:ui/providers/APIs.dart';
import 'package:ui/providers/settings.dart';
import 'package:ui/widgets/utils.dart';
import 'package:ui/widgets/progress_indicator.dart';
import 'package:ui/widgets/widgets.dart';
import 'package:url_launcher/url_launcher.dart';

class SystemPage extends ConsumerStatefulWidget {
Expand All @@ -28,8 +29,8 @@ class _SystemPageState extends ConsumerState<SystemPage> {
ExpansionTile(
expandedCrossAxisAlignment: CrossAxisAlignment.stretch,
initiallyExpanded: true,
childrenPadding: EdgeInsets.all(20),
title: Text("日志"),
childrenPadding: const EdgeInsets.all(20),
title: const Text("日志"),
children: [
logs.when(
data: (list) {
Expand Down Expand Up @@ -59,7 +60,62 @@ class _SystemPageState extends ConsumerState<SystemPage> {
],
),
ExpansionTile(
title: Text("关于"),
expandedCrossAxisAlignment: CrossAxisAlignment.stretch,
initiallyExpanded: true,
childrenPadding: const EdgeInsets.all(20),
title: const Text("定时任务"),
children: [
logs.when(
data: (list) {
return DataTable(columns: const [
DataColumn(label: Text("任务")),
DataColumn(label: Text("间隔")),
DataColumn(label: Text("手动触发"))
], rows: [
DataRow(cells: [
const DataCell(Text("检查并处理已完成任务")),
const DataCell(Text("每分钟")),
DataCell(LoadingIconButton(
icon: Icons.not_started,
onPressed: () =>
APIs.triggerCronJob("check_running_tasks"),
))
]),
DataRow(cells: [
const DataCell(Text("下载监控中的剧集和电影")),
const DataCell(Text("每小时")),
DataCell(LoadingIconButton(
icon: Icons.not_started,
onPressed: () => APIs.triggerCronJob(
"check_available_medias_to_download"),
))
]),
DataRow(cells: [
const DataCell(Text("更新监控列表")),
const DataCell(Text("每小时")),
DataCell(IconButton(
icon: const Icon(Icons.not_started),
onPressed: () =>
APIs.triggerCronJob("update_import_lists"),
))
]),
DataRow(cells: [
const DataCell(Text("更新最新剧集信息")),
const DataCell(Text("每天2次")),
DataCell(LoadingIconButton(
icon: Icons.not_started,
onPressed: () =>
APIs.triggerCronJob("check_series_new_release"),
))
]),
]);
},
error: (err, trace) => Text("$err"),
loading: () => const MyProgressIndicator())
],
),
ExpansionTile(
title: const Text("关于"),
expandedCrossAxisAlignment: CrossAxisAlignment.center,
initiallyExpanded: true,
children: [
Expand Down
4 changes: 2 additions & 2 deletions ui/lib/widgets/widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class _MySliderState extends State<MyRangeSlider> {
}

class LoadingIconButton extends StatefulWidget {
LoadingIconButton({required this.onPressed, required this.icon, this.tooltip});
const LoadingIconButton({super.key, required this.onPressed, required this.icon, this.tooltip});
final Future<void> Function() onPressed;
final IconData icon;
final String? tooltip;
Expand Down Expand Up @@ -187,7 +187,7 @@ class _LoadingIconButtonState extends State<LoadingIconButton> {
}

class LoadingTextButton extends StatefulWidget {
LoadingTextButton({required this.onPressed, required this.label});
const LoadingTextButton({super.key, required this.onPressed, required this.label});
final Future<void> Function() onPressed;
final Widget label;

Expand Down

0 comments on commit bf608f9

Please sign in to comment.