| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- namespace App\Module\Cleanup\AdminControllers\Actions;
- use App\Module\Cleanup\Services\CleanupService;
- use Dcat\Admin\Grid\RowAction;
- use Dcat\Admin\Actions\Response;
- use Illuminate\Http\Request;
- /**
- * 暂停任务Action
- *
- * 用于暂停正在执行的清理任务
- */
- class PauseTaskAction extends RowAction
- {
- /**
- * 按钮标题
- */
- protected $title = '暂停任务';
- /**
- * 处理请求
- */
- public function handle(Request $request)
- {
- try {
- $taskId = $this->getKey();
-
- // 调用服务暂停任务
- $result = CleanupService::pauseTask($taskId);
-
- if (!$result['success']) {
- return $this->response()
- ->error('暂停失败:' . $result['message']);
- }
-
- return $this->response()
- ->success('任务暂停成功!')
- ->detail('任务已暂停,可以稍后恢复执行。')
- ->refresh();
-
- } catch (\Exception $e) {
- return $this->response()
- ->error('暂停失败:' . $e->getMessage());
- }
- }
- /**
- * 确认对话框
- */
- public function confirm()
- {
- return [
- '确认暂停任务?',
- '任务将在当前批次完成后暂停,可以稍后恢复执行。'
- ];
- }
- /**
- * 权限检查
- */
- public function allowed()
- {
- $row = $this->row;
- return in_array($row->status, [2, 3]); // 备份中或执行中的任务可以暂停
- }
- }
|