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 (original work) Open Assessment Technologies SA;
19 *
20 *
21 */
22
23namespace oat\tao\model\actionQueue;
24
25use oat\oatbox\user\User;
26
27/**
28 * Interface ActionQueue
29 *
30 * configuration example:
31 * ```php
32 * new InstantActionQueue([
33 *      //persistence to store actions in queue
34 *      InstantActionQueue::OPTION_PERSISTENCE => 'key_value_persistence',
35 *
36 *      //registered actions
37 *      InstantActionQueue::OPTION_ACTIONS => [
38 *          SomeAction::class => [
39 *              //limit of active actions. 0 means that queue is disabled for this action
40 *              InstantActionQueue::ACTION_PARAM_LIMIT => 10,
41 *              //time to live
42 *              InstantActionQueue::ACTION_PARAM_TTL => 30,
43 *          ]
44 *      ]
45 *  ]);
46 * ```
47 *
48 * @author Aleh Hutnikau, <hutnikau@1pt.com>
49 * @package oat\tao\model\actionQueue
50 */
51interface ActionQueue
52{
53    public const SERVICE_ID = 'tao/ActionQueue';
54
55    /**
56     * List of registered actions to be performed using action queue
57     */
58    public const OPTION_ACTIONS = 'actions';
59
60    /**
61     * Persistence identifier
62     */
63    public const OPTION_PERSISTENCE = 'persistence';
64
65    /**
66     * Limit of actions in progress.
67     * If number of active actions will be more that this value then action will be put into queue
68     */
69    public const ACTION_PARAM_LIMIT = 'limit';
70
71    /**
72     * Time to live for place in the queue (seconds). Configures per actions.
73     */
74    public const ACTION_PARAM_TTL = 'ttl';
75
76    /**
77     * @param QueuedAction $action
78     * @param User $user user which tries to perform action
79     * @return boolean
80     */
81    public function perform(QueuedAction $action, User $user = null);
82
83    /**
84     * @param QueuedAction $action
85     * @param User $user
86     * @return integer
87     */
88    public function getPosition(QueuedAction $action, User $user = null);
89
90    /**
91     * @param QueuedAction $action
92     * @return integer Number of removed positions
93     */
94    public function clearAbandonedPositions(QueuedAction $action);
95
96    /**
97     * @param QueuedAction $action
98     * @return bool
99     */
100    public function isActionEnabled(QueuedAction $action): bool;
101}