1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
scriptqueue.php
См. документацию.
1<?php
2
3namespace Bitrix\Bizproc\Script\Entity;
4
5use Bitrix\Bizproc\Script\Queue\Status;
6use Bitrix\Main;
7use Bitrix\Main\ORM\Fields\ExpressionField;
8
25class ScriptQueueTable extends Main\Entity\DataManager
26{
30 public static function getTableName()
31 {
32 return 'b_bp_script_queue';
33 }
34
38 public static function getMap()
39 {
40 return [
41 'ID' => [
42 'data_type' => 'integer',
43 'primary' => true,
44 'autocomplete' => true,
45 ],
46 'SCRIPT_ID' => [
47 'data_type' => 'integer'
48 ],
49 'STARTED_DATE' => [
50 'data_type' => 'datetime'
51 ],
52 'STARTED_BY' => [
53 'data_type' => 'integer'
54 ],
55 'STARTED_USER' => [
56 'data_type' => Main\UserTable::class,
57 'reference' => [
58 '=this.STARTED_BY' => 'ref.ID'
59 ],
60 'join_type' => 'LEFT',
61 ],
62 'STATUS' => [
63 'data_type' => 'integer'
64 ],
65 'MODIFIED_DATE' => [
66 'data_type' => 'datetime'
67 ],
68 'MODIFIED_BY' => [
69 'data_type' => 'integer',
70 'default_value' => 0,
71 ],
72 new Main\ORM\Fields\ArrayField('WORKFLOW_PARAMETERS'),
73 ];
74 }
75
82 public static function getDocumentCounters(int $queueId): array
83 {
84 $scriptQueueRows =
85 ScriptQueueDocumentTable::query()
86 ->addSelect('STATUS')
87 ->addSelect(new ExpressionField('CNT', 'COUNT(1)'))
88 ->where('QUEUE_ID', $queueId)
89 ->setGroup('STATUS')
90 ->exec()
91 ->fetchAll();
92 ;
93
94 $all = 0;
95 $queued = 0;
96 foreach ($scriptQueueRows as $scriptGroupByStatus)
97 {
98 $all += (int)$scriptGroupByStatus['CNT'];
99 if ((int)$scriptGroupByStatus['STATUS'] === Status::QUEUED)
100 {
101 $queued = (int)$scriptGroupByStatus['CNT'];
102 }
103 }
104
105 return [
106 'all' => $all,
107 'queued' => $queued,
108 'completed' => $all - $queued
109 ];
110 }
111
112 public static function getNextQueuedDocument(int $queueId): ?EO_ScriptQueueDocument
113 {
114 $document = ScriptQueueDocumentTable::getList([
115 'filter' => [
116 '=QUEUE_ID' => $queueId,
117 '=STATUS' => Status::QUEUED,
118 ],
119 'order' => ['ID' => 'ASC'],
120 'limit' => 1
121 ])->fetchObject();
122
123 return $document;
124 }
125
126 public static function markTerminated(int $queueId, int $userId)
127 {
128 static::update(
129 $queueId,
130 [
131 'STATUS' => Status::TERMINATED,
132 'MODIFIED_BY' => $userId
133 ]
134 );
135
136 $docResult = ScriptQueueDocumentTable::getList([
137 'filter' => [
138 '=QUEUE_ID' => $queueId,
139 '=STATUS' => Status::QUEUED,
140 ],
141 'select' => ['ID']
142 ]);
143
144 $docIds = array_column($docResult->fetchAll(), 'ID');
145
146 ScriptQueueDocumentTable::updateMulti($docIds, ['STATUS' => Status::TERMINATED], true);
147 }
148
149 public static function markExecuting(int $queueId)
150 {
151 static::update($queueId, ['STATUS' => Status::EXECUTING]);
152 }
153
154 public static function markCompleted(int $queueId)
155 {
156 static::update($queueId, ['STATUS' => Status::COMPLETED]);
157 }
158
159 public static function deleteByScript(int $scriptId)
160 {
161 $result = static::getList(['filter' => ['=SCRIPT_ID' => $scriptId], 'select' => ['ID']]);
162
163 foreach ($result as $row)
164 {
165 static::delete($row['ID']);
167 }
168 }
169
171 {
173
174 $fields = $event->getParameter('fields');
175 $modifyFields = ['MODIFIED_DATE' => new Main\Type\DateTime()];
176
177 if(!isset($fields['MODIFIED_BY']))
178 {
179 $modifyFields['MODIFIED_BY'] = 0;
180 }
181
182 $result->modifyFields($modifyFields);
183
184 return $result;
185 }
186}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static markCompleted(int $queueId)
Определения scriptqueue.php:154
static getDocumentCounters(int $queueId)
Определения scriptqueue.php:82
static deleteByScript(int $scriptId)
Определения scriptqueue.php:159
static onBeforeUpdate(Main\ORM\Event $event)
Определения scriptqueue.php:170
static getNextQueuedDocument(int $queueId)
Определения scriptqueue.php:112
static markTerminated(int $queueId, int $userId)
Определения scriptqueue.php:126
static markExecuting(int $queueId)
Определения scriptqueue.php:149
Определения event.php:5
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$event
Определения prolog_after.php:141
$fields
Определения yandex_run.php:501