Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
n/a
0 / 0
n/a
0 / 0
CRAP
n/a
0 / 0
1<?php
2
3/**
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; under version 2
7 * of the License (non-upgradable).
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 *
18 * Copyright (c) 2017-2020 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
19 *
20 */
21
22namespace oat\tao\model\taskQueue\TaskLog\Broker;
23
24use common_report_Report as Report;
25use DateTime;
26use oat\tao\model\taskQueue\Task\TaskInterface;
27use oat\tao\model\taskQueue\TaskLog\CollectionInterface;
28use oat\tao\model\taskQueue\TaskLog\Entity\EntityInterface;
29use oat\tao\model\taskQueue\TaskLog\TaskLogFilter;
30use oat\tao\model\taskQueue\TaskLog\TasksLogsStats;
31use Zend\ServiceManager\ServiceLocatorAwareInterface;
32
33/**
34 * @author Gyula Szucs <gyula@taotesting.com>
35 */
36interface TaskLogBrokerInterface extends ServiceLocatorAwareInterface
37{
38    public const DEFAULT_CONTAINER_NAME = 'task_log';
39
40    public const COLUMN_ID = 'id';
41    public const COLUMN_PARENT_ID = 'parent_id';
42    public const COLUMN_MASTER_STATUS = 'master_status';
43    public const COLUMN_TASK_NAME = 'task_name';
44    public const COLUMN_PARAMETERS = 'parameters';
45    public const COLUMN_LABEL = 'label';
46    public const COLUMN_STATUS = 'status';
47    public const COLUMN_OWNER = 'owner';
48    public const COLUMN_REPORT = 'report';
49    public const COLUMN_CREATED_AT = 'created_at';
50    public const COLUMN_UPDATED_AT = 'updated_at';
51
52    /**
53     * Creates the container where the task logs will be stored.
54     */
55    public function createContainer(): void;
56
57    /**
58     * RDS table name.
59     */
60    public function getTableName(): string;
61
62    /**
63     * Inserts a new task log with status for a task.
64     */
65    public function add(TaskInterface $task, string $status, string $label = null): void;
66
67    /**
68     * Update the status of a task.
69     *
70     * The previous status can be used for querying the record.
71     *
72     * @return int count of touched records
73     */
74    public function updateStatus(string $taskId, string $newStatus, string $prevStatus = null): int;
75
76    /**
77     * Gets the status of a task.
78     */
79    public function getStatus(string $taskId): string;
80
81    /**
82     * Add a report for a task. New status can be supplied as well.
83     */
84    public function addReport(string $taskId, Report $report, string $newStatus = null): int;
85
86    /**
87     * Gets a report for a task.
88     */
89    public function getReport(string $taskId): ?Report;
90
91    /**
92     * Search for task logs by defined filters.
93     * @return CollectionInterface|EntityInterface[]
94     */
95    public function search(TaskLogFilter $filter): iterable;
96
97    /**
98     * Counts task logs by defined filters.
99     */
100    public function count(TaskLogFilter $filter): int;
101
102    public function getStats(TaskLogFilter $filter): TasksLogsStats;
103
104    /**
105     * Fetch task execution times for given date range
106     * Formatted with task id as key and execution time as value
107     *
108     * @param DateTime $from
109     * @param DateTime $to
110     * @return array `[ 'task1'=> 'time-in-second', 'task-id-1' => 10]`
111     */
112    public function getTaskExecutionTimesByDateRange(DateTime $from, DateTime $to): array;
113
114    /**
115     * Setting the status to archive, the record is kept. (Soft Delete)
116     */
117    public function archive(EntityInterface $entity): bool;
118
119    /**
120     * Setting the status to cancelled, the record is kept. (Soft Delete)
121     */
122    public function cancel(EntityInterface $entity): bool;
123
124    public function archiveCollection(CollectionInterface $collection): int;
125
126    public function cancelCollection(CollectionInterface $collection): int;
127
128    /**
129     * Delete the task log by id. (Hard Delete)
130     */
131    public function deleteById(string $taskId): bool;
132}