Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ai_interpolator
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
ai_interpolator
Commits
0981d205
Commit
0981d205
authored
1 year ago
by
Marcus Johansson
Committed by
Marcus Johansson
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3416665
by Marcus_Johansson: Status field is not updated on queueworker
parent
cc744c7e
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Pipeline
#81783
passed
1 year ago
Stage: build
Stage: validate
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Plugin/QueueWorker/InterpolatorFieldData.php
+49
-2
49 additions, 2 deletions
src/Plugin/QueueWorker/InterpolatorFieldData.php
with
49 additions
and
2 deletions
src/Plugin/QueueWorker/InterpolatorFieldData.php
+
49
−
2
View file @
0981d205
...
...
@@ -3,9 +3,11 @@
namespace
Drupal\ai_interpolator\Plugin\QueueWorker
;
use
Drupal\ai_interpolator
\AiInterpolatorRuleRunner
;
use
Drupal\ai_interpolator
\AiInterpolatorStatusField
;
use
Drupal\ai_interpolator
\Exceptions\AiInterpolatorRequestErrorException
;
use
Drupal\ai_interpolator
\Exceptions\AiInterpolatorResponseErrorException
;
use
Drupal\ai_interpolator
\Exceptions\AiInterpolatorRuleNotFoundException
;
use
Drupal\Core\Database\Connection
;
use
Drupal\Core\Entity\EntityTypeManagerInterface
;
use
Drupal\Core\Logger\LoggerChannelFactoryInterface
;
use
Drupal\Core\Plugin\ContainerFactoryPluginInterface
;
...
...
@@ -38,6 +40,11 @@ class InterpolatorFieldData extends QueueWorkerBase implements ContainerFactoryP
*/
protected
LoggerChannelFactoryInterface
$loggerFactory
;
/**
* The Drupal database connection.
*/
protected
Connection
$db
;
/**
* Constructor.
*
...
...
@@ -53,12 +60,15 @@ class InterpolatorFieldData extends QueueWorkerBase implements ContainerFactoryP
* The entity type manager.
* @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $loggerFactory
* The logger factory.
* @param \Drupal\Core\Database\Connection $db
* The database connection.
*/
final
public
function
__construct
(
array
$configuration
,
$plugin_id
,
$plugin_definition
,
AiInterpolatorRuleRunner
$aiRunner
,
EntityTypeManagerInterface
$entityTypeManager
,
LoggerChannelFactoryInterface
$loggerFactory
)
{
final
public
function
__construct
(
array
$configuration
,
$plugin_id
,
$plugin_definition
,
AiInterpolatorRuleRunner
$aiRunner
,
EntityTypeManagerInterface
$entityTypeManager
,
LoggerChannelFactoryInterface
$loggerFactory
,
Connection
$db
)
{
parent
::
__construct
(
$configuration
,
$plugin_id
,
$plugin_definition
);
$this
->
aiRunner
=
$aiRunner
;
$this
->
entityTypeManager
=
$entityTypeManager
;
$this
->
loggerFactory
=
$loggerFactory
;
$this
->
db
=
$db
;
}
/**
...
...
@@ -71,7 +81,8 @@ class InterpolatorFieldData extends QueueWorkerBase implements ContainerFactoryP
$plugin_definition
,
$container
->
get
(
'ai_interpolator.rule_runner'
),
$container
->
get
(
'entity_type.manager'
),
$container
->
get
(
'logger.factory'
)
$container
->
get
(
'logger.factory'
),
$container
->
get
(
'database'
)
);
}
...
...
@@ -91,6 +102,10 @@ class InterpolatorFieldData extends QueueWorkerBase implements ContainerFactoryP
$entity
=
$this
->
aiRunner
->
generateResponse
(
$newEntity
,
$data
[
'fieldDefinition'
],
$data
[
'interpolatorConfig'
]);
// Turn off the hook.
_ai_interpolator_entity_can_save_toggle
(
FALSE
);
// Check if its the last queue item for the entity and reset processing.
if
(
$this
->
lastInQueue
(
$entity
->
getEntityTypeId
(),
$entity
->
id
()))
{
$entity
->
set
(
'ai_interpolator_status'
,
AiInterpolatorStatusField
::
STATUS_FINISHED
);
}
// Resave.
$success
=
$entity
->
save
();
// Turn on the hook.
...
...
@@ -122,7 +137,39 @@ class InterpolatorFieldData extends QueueWorkerBase implements ContainerFactoryP
'%message'
=>
$e
->
getMessage
(),
]);
}
// Since it failed.
$entity
=
$this
->
entityTypeManager
->
getStorage
(
$data
[
'entity_type'
])
->
load
(
$data
[
'entity_id'
]);
$entity
->
set
(
'ai_interpolator_status'
,
AiInterpolatorStatusField
::
STATUS_FAILED
);
$entity
->
save
();
}
/**
* Check if its the last processed item for that entity.
*
* @param string $entityType
* The entity type.
* @param int $entityId
* The entity id.
*
* @return bool
* If its the last item.
*/
protected
function
lastInQueue
(
$entityType
,
$entityId
)
{
$query
=
$this
->
db
->
select
(
'queue'
,
'q'
);
$query
->
fields
(
'q'
,
[
'data'
])
->
condition
(
'name'
,
'ai_interpolator_field_modifier'
);
$result
=
$query
->
execute
();
// Amount found.
$amount
=
0
;
foreach
(
$result
as
$record
)
{
$data
=
unserialize
(
$record
->
data
,
[
'allowed_classes'
=>
FALSE
]);
if
(
$data
[
'entity_type'
]
===
$entityType
&&
$data
[
'entity_id'
]
===
$entityId
)
{
$amount
++
;
}
}
// Since itself still counts, 1 item is the last.
return
$amount
<=
1
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment