colgatto/mint

Linux的背景任务管理器,PHP后端 + 网页GUI

1.1.0 2021-10-05 13:32 UTC

This package is auto-updated.

Last update: 2024-09-05 20:22:56 UTC


README

从网页GUI在Linux上创建、监控和管理后台任务

任务监控器

taskMonitor

任务列表

taskList

安装

composer require colgatto/mint

确保Mint目录有正确的权限,如果PHP不能在其中创建文件,Mint将无法工作

从项目目录运行以下命令以给予Mint正确的权限

sudo chown www-data:www-data -R ./vendor/colgatto/mint

用法

www/api.php

<?php

require_once __DIR__ . '/../vendor/autoload.php';

use Mint\ApiEngine;

//tell the manager where are located the tasks
ApiEngine::start(__DIR__ . '/../tasks');

?>

www/index.php

<?php 

require_once __DIR__ . '/../vendor/autoload.php';

use Mint\WebGui;

WebGui::start();

?>

tasks/example.php

<?php
require_once __DIR__ . '/../vendor/autoload.php';

use Mint\Task;
use Mint\Settings;

//define task info
define('TASK_NAME', 'Example Task');
define('TASK_DESCRIPTION', 'use me as template for new task');
define('TASK_PARAMS', [
	'int_param' => Settings::TYPE_INT,
	'float_param' => Settings::TYPE_FLOAT,
	'string_param' => Settings::TYPE_STRING,
	'bool_param' => Settings::TYPE_BOOL,
]);

//start the task
//use Task::cli_start(true) if you want singleton task (block multiple instances of same task)
$task = Task::cli_start();

//get task parameters
$int_param = $task->get('int_param');
$float_param = $task->get('float_param');
$string_param = $task->get('string_param');
$bool_param = $task->get('bool_param');

//log stuff
Task::log(TASK_NAME . ' Started');

Task::log('int_param: ' . $int_param);
Task::log('float_param: ' . $float_param);
Task::log('string_param: ' . $string_param);
Task::log('bool_param: ' . $bool_param);

//setup progress bar
$task->setMaxProgress(10);

//do stuff
Task::log('wait 10 seconds then exit');
for ($i=0; $i < 10; $i++) {
	Task::log( ($i+1) );
	$task->incProgress(); //increment progress bar by 1
	sleep(1); //wait
}

//terminate task
$task->terminate();

?>