Permalink
Browse files

Rework core.task and action.scheduler to replace old system by new ta…

…sk service.
  • Loading branch information...
1 parent 8a2b9cd commit b63e19adca6bb86e921b6cd70684050526602480 @cdujeu cdujeu committed Jul 20, 2016
View
@@ -6,6 +6,7 @@
/plugins/access.inbox/res/build
/plugins/core.mailer/js/build
/plugins/gui.ajax/res/js/ui/reactjs/build/
+/plugins/core.tasks/vendor
.idea/
data/cache/*
data/files/*
@@ -7,8 +7,5 @@
"psr-4": {
"Pydio\\Action\\Scheduler\\": "./src"
}
- },
- "require": {
- "mtdowling/cron-expression": "^1.1"
}
}
Oops, something went wrong.
@@ -7,5 +7,8 @@
"psr-4": {
"Pydio\\Tasks\\": "./src"
}
+ },
+ "require": {
+ "mtdowling/cron-expression": "^1.1"
}
}
@@ -1,17 +1,24 @@
CREATE TABLE IF NOT EXISTS `ajxp_tasks` (
`uid` varchar(255) NOT NULL,
+ `type` int(11) NOT NULL,
+ `parent_uid` varchar(255) DEFAULT NULL,
`flags` int(11) NOT NULL,
`label` varchar(255) NOT NULL,
`userId` varchar(255) NOT NULL,
`wsId` varchar(32) NOT NULL,
`status` int(11) NOT NULL,
`status_msg` mediumtext NOT NULL,
`progress` int(11) NOT NULL,
- `schedule` text NOT NULL,
+ `schedule` int(11) NOT NULL,
+ `schedule_value` varchar(255) DEFAULT NULL,
`action` text NOT NULL,
`parameters` mediumtext NOT NULL,
`nodes` text NOT NULL,
+ `creation_date` int(11) NOT NULL DEFAULT '0' COMMENT 'Date of creation of the job',
+ `status_update` int(11) NOT NULL DEFAULT '0' COMMENT 'Last time the status was updated',
PRIMARY KEY (`uid`),
KEY `userId` (`userId`,`status`),
- INDEX (nodes(40))
+ KEY `type` (`type`),
+ KEY `schedule` (`schedule`),
+ FULLTEXT KEY `nodes` (`nodes`)
) DEFAULT CHARSET=utf8 COMMENT='Task persistence layer';
@@ -1,20 +1,27 @@
CREATE TABLE ajxp_tasks (
uid VARCHAR(255) NOT NULL ,
+ type INTEGER NOT NULL,
+ parent_uid VARCHAR(255) DEFAULT NULL,
flags INTEGER NOT NULL,
label VARCHAR(255) NOT NULL,
userId VARCHAR(255) NOT NULL,
wsId VARCHAR(32) NOT NULL,
status INTEGER NOT NULL,
status_msg VARCHAR(500) NOT NULL,
progress INTEGER NOT NULL,
- schedule VARCHAR(500) NOT NULL,
+ schedule INTEGER NOT NULL,
+ schedule_value VARCHAR (255) DEFAULT NULL,
action VARCHAR(255) NOT NULL,
parameters VARCHAR(500) NOT NULL,
- nodes VARCHAR(500) NOT NULL
+ nodes VARCHAR(500) NOT NULL,
+ creation_date INTEGER NOT NULL DEFAULT '0' COMMENT 'Date of creation of the job',
+ status_update INTEGER NOT NULL DEFAULT '0' COMMENT 'Last time the status was updated',
);
CREATE INDEX ajxp_task_idx ON ajxp_tasks ('uid');
CREATE INDEX ajxp_task_usr_idx ON ajxp_tasks ('userId');
CREATE INDEX ajxp_task_status_idx ON ajxp_tasks ('status');
+CREATE INDEX ajxp_task_type ON ajxp_tasks ('type');
+CREATE INDEX ajxp_task_schedule ON ajxp_tasks ('schedule');
CREATE INDEX ajxp_task_nodes_idx ON ajxp_tasks ('nodes');
@@ -1,19 +1,26 @@
CREATE TABLE ajxp_tasks (
uid text NOT NULL ,
+ type INTEGER NOT NULL,
+ parent_uid text DEFAULT NULL,
flags integer NOT NULL,
label text NOT NULL,
userId text NOT NULL,
wsId text NOT NULL,
status INTEGER NOT NULL,
status_msg text NOT NULL,
progress INTEGER NOT NULL,
- schedule text NOT NULL,
+ schedule INTEGER NOT NULL,
+ schedule_value text DEFAULT NULL,
action text NOT NULL,
parameters text NOT NULL,
- nodes text NOT NULL
+ nodes text NOT NULL,
+ creation_date INTEGER NOT NULL DEFAULT 0,
+ status_update INTEGER NOT NULL DEFAULT 0,
);
CREATE INDEX ajxp_task_idx ON ajxp_tasks (uid);
CREATE INDEX ajxp_task_usr_idx ON ajxp_tasks (userId);
CREATE INDEX ajxp_task_status_idx ON ajxp_tasks (status);
+CREATE INDEX ajxp_task_type ON ajxp_tasks (type);
+CREATE INDEX ajxp_task_schedule ON ajxp_tasks (schedule);
CREATE INDEX ajxp_task_nodes_idx ON ajxp_tasks (nodes);
@@ -28,6 +28,10 @@
defined('AJXP_EXEC') or die('Access not allowed');
+/**
+ * Interface ITasksProvider
+ * @package Pydio\Tasks
+ */
interface ITasksProvider
{
/**
@@ -63,6 +67,11 @@ public function deleteTask($taskId);
public function getPendingTasks();
/**
+ * @return Task[]
+ */
+ public function getScheduledTasks();
+
+ /**
* @param UserInterface $user
* @param RepositoryInterface $repository
* @return Task[]
@@ -71,7 +80,6 @@ public function getCurrentRunningTasks($user, $repository);
/**
* @param AJXP_Node $node
- * @param $active
* @return Task[]
*/
public function getActiveTasksForNode(AJXP_Node $node);
@@ -80,7 +88,16 @@ public function getActiveTasksForNode(AJXP_Node $node);
* @param UserInterface $user
* @param RepositoryInterface $repository
* @param int $status
+ * @param int $scheduleType
+ * @param int $taskType
+ * @param string $parentUid
+ * @return \Pydio\Tasks\Task[]
+ */
+ public function getTasks($user = null, $repository = null, $status = -1, $scheduleType = -1, $taskType = Task::TYPE_USER, $parentUid = "");
+
+ /**
+ * @param string $taskId
* @return Task[]
*/
- public function getTasks($user = null, $repository = null, $status = -1);
+ public function getChildrenTasks($taskId);
}
@@ -24,6 +24,8 @@
use Pydio\Access\Core\Model\AJXP_Node;
use Pydio\Access\Core\Model\Repository;
use Pydio\Conf\Core\AbstractUser;
+use Pydio\Core\Model\RepositoryInterface;
+use Pydio\Core\Model\UserInterface;
use Pydio\Tasks\Task;
use Pydio\Tasks\Schedule;
@@ -99,12 +101,15 @@ public function getActiveTasksForNode(AJXP_Node $node)
}
/**
- * @param \Pydio\Conf\Core\AbstractUser $user
- * @param \Pydio\Access\Core\Model\Repository $repository
+ * @param UserInterface $user
+ * @param RepositoryInterface $repository
* @param int $status
- * @return Task[]
+ * @param int $scheduleType
+ * @param int $taskType
+ * @param string $parentUid
+ * @return \Pydio\Tasks\Task[]
*/
- public function getTasks($user = null, $repository = null, $status = -1)
+ public function getTasks($user = null, $repository = null, $status = -1, $scheduleType = -1, $taskType = Task::TYPE_USER, $parentUid = "")
{
$t1 = new Task();
$t1->setAction("fake-task-action");
@@ -121,4 +126,21 @@ public function getCurrentRunningTasks($user, $repository)
{
// TODO: Implement getCurrentRunningTasks() method.
}
+
+ /**
+ * @return Task[]
+ */
+ public function getScheduledTasks()
+ {
+ // TODO: Implement getScheduledTasks() method.
+ }
+
+ /**
+ * @param string $taskId
+ * @return Task[]
+ */
+ public function getChildrenTasks($taskId){
+
+ }
+
}
@@ -21,40 +21,52 @@
namespace Pydio\Tasks\Providers;
use Pydio\Access\Core\Model\AJXP_Node;
-use Pydio\Access\Core\Model\Repository;
-use Pydio\Conf\Core\AbstractUser;
-
+use Pydio\Core\Model\RepositoryInterface;
+use Pydio\Core\Model\UserInterface;
use Pydio\Tasks\ITasksProvider;
use Pydio\Tasks\Schedule;
use Pydio\Tasks\Task;
defined('AJXP_EXEC') or die('Access not allowed');
-
-
-
+/**
+ * Class SqlTasksProvider
+ * @package Pydio\Tasks\Providers
+ */
class SqlTasksProvider implements ITasksProvider
{
-
+ /**
+ * Serialize task for storing in ajxp_tasks
+ * @param Task $task
+ * @param bool $removeId
+ * @return array
+ */
protected function taskToDBValues(Task $task, $removeId = false){
$values = [
- "flags" => $task->getFlags(),
- "label" => $task->getLabel(),
- "userId" => $task->getUserId(),
- "wsId" => $task->getWsId(),
- "status" => $task->getStatus(),
- "status_msg"=> $task->getStatusMessage(),
- "progress" => $task->getProgress(),
- "schedule" => json_encode($task->getSchedule()),
- "action" => $task->getAction(),
- "parameters"=> json_encode($task->getParameters()),
- "nodes" => ""
+ "type" => $task->getType(),
+ "parent_uid" => $task->getParentId(),
+ "flags" => $task->getFlags(),
+ "label" => $task->getLabel(),
+ "userId" => $task->getUserId(),
+ "wsId" => $task->getWsId(),
+ "status" => $task->getStatus(),
+ "status_msg" => $task->getStatusMessage(),
+ "progress" => $task->getProgress(),
+ "schedule" => $task->getSchedule()->getType(),
+ "schedule_value" => $task->getSchedule()->getValue(),
+ "action" => $task->getAction(),
+ "parameters" => json_encode($task->getParameters()),
+ "nodes" => ""
];
if(count($task->nodes)){
$values["nodes"] = "|||".implode("|||", $task->nodes)."|||";
}
if(!$removeId){
+ // This is a creation
+ $values["creation_date"] = time();
$values = array_merge(["uid" => $task->getId()], $values);
+ }else{
+ $values["status_update"] = time();
}
return $values;
}
@@ -66,15 +78,21 @@ protected function taskToDBValues(Task $task, $removeId = false){
protected function taskFromDBValues(\DibiRow $values){
$task = new Task();
$task->setId($values["uid"]);
+ $task->setType($values["type"]);
+ if(!empty($values["parent_uid"])){
+ $task->setParentId($values["parent_uid"]);
+ }
$task->setFlags($values["flags"]);
$task->setLabel($values["label"]);
$task->setUserId($values["userId"]);
$task->setWsId($values["wsId"]);
$task->setStatus($values["status"]);
$task->setStatusMessage($values["status_msg"]);
$task->setProgress($values["progress"]);
- $task->setSchedule(Schedule::fromJson($values["schedule"]));
+ $task->setSchedule(new Schedule($values["schedule"], $values["schedule_value"]));
$task->setAction($values["action"]);
+ $task->setCreationDate($values["creation_date"]);
+ $task->setStatusChangeDate($values["status_update"]);
$task->setParameters(json_decode($values["parameters"], true));
$nodes = explode("|||", trim($values["nodes"], "|||"));
foreach ($nodes as $node) {
@@ -103,6 +121,7 @@ public function getTaskById($taskId)
foreach ($res->fetchAll() as $row) {
return $this->taskFromDBValues($row);
}
+ return null;
}
/**
@@ -136,8 +155,31 @@ public function getPendingTasks()
}
/**
- * @param AbstractUser $user
- * @param Repository $repository
+ * @return Task[]
+ */
+ public function getScheduledTasks(){
+ return $this->getTasks(null, null, -1, Schedule::TYPE_RECURRENT, Task::TYPE_ADMIN, AJXP_FILTER_EMPTY);
+ }
+
+ /**
+ * @param string $taskId
+ * @return Task[]
+ */
+ public function getChildrenTasks($taskId){
+ $tasks = [];
+ $where = [];
+ $where[] = array("[parent_uid] = %s", $taskId);
+ $res = \dibi::query('SELECT * FROM [ajxp_tasks] WHERE %and', $where);
+ foreach ($res->fetchAll() as $row) {
+ $tasks[] = $this->taskFromDBValues($row);
+ }
+ return $tasks;
+ }
+
+
+ /**
+ * @param UserInterface $user
+ * @param RepositoryInterface $repository
* @return Task[]
*/
public function getCurrentRunningTasks($user, $repository)
@@ -156,7 +198,6 @@ public function getCurrentRunningTasks($user, $repository)
/**
* @param AJXP_Node $node
- * @param $active
* @return \Pydio\Tasks\Task[]
*/
public function getActiveTasksForNode(AJXP_Node $node)
@@ -174,12 +215,15 @@ public function getActiveTasksForNode(AJXP_Node $node)
}
/**
- * @param AbstractUser $user
- * @param Repository $repository
+ * @param UserInterface $user
+ * @param RepositoryInterface $repository
* @param int $status
- * @return Task[]
+ * @param int $scheduleType
+ * @param int $taskType
+ * @param string $parentUid
+ * @return \Pydio\Tasks\Task[]
*/
- public function getTasks($user = null, $repository = null, $status = -1)
+ public function getTasks($user = null, $repository = null, $status = -1, $scheduleType = -1, $taskType = Task::TYPE_USER, $parentUid = "")
{
$tasks = [];
$where = [];
@@ -192,6 +236,19 @@ public function getTasks($user = null, $repository = null, $status = -1)
if($status !== -1){
$where[] = array("[status] = %i", $status);
}
+ if($scheduleType !== -1){
+ $where[] = array("[schedule] = %i", $scheduleType);
+ }
+ if($taskType !== -1){
+ $where[] = array("[type] = %i", $taskType);
+ }
+ if(!empty($parentUid)){
+ if($parentUid === AJXP_FILTER_EMPTY){
+ $where[] = array("[parent_uid] IS NULL");
+ }else{
+ $where[] = array("[parent_uid] = %s", $parentUid);
+ }
+ }
$res = \dibi::query('SELECT * FROM [ajxp_tasks] WHERE %and', $where);
foreach ($res->fetchAll() as $row) {
$tasks[] = $this->taskFromDBValues($row);
Oops, something went wrong.

0 comments on commit b63e19a

Please sign in to comment.