Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISSUE-97: Time out management and better entity listing handling #101

Open
wants to merge 20 commits into
base: 0.9.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
985883b
Remove the CRON entry for index.
DiegoPino Sep 30, 2024
27e6167
mmm... restoring CRON and actually using configured/chosen queues
DiegoPino Oct 1, 2024
aaa2055
Clean up queue assignment
DiegoPino Jan 9, 2025
50129c7
remove error log
DiegoPino Jan 17, 2025
4fa8e73
Clean up SBR Entity list builder and interface
DiegoPino Jan 17, 2025
601675d
Cleanups for further hierarchies in the abstractprocessor
DiegoPino Jan 17, 2025
fbc4458
Adds fixed margin and the new '/image/vision_transformer' endpoint
DiegoPino Jan 17, 2025
3ac7c50
adds the now required @label property to this action
DiegoPino Jan 23, 2025
704bbe9
adds new Binary/Executable Timeout. I added this as a config options
DiegoPino Jan 23, 2025
744bbe1
Adds the new timeout config options to processors that use external b…
DiegoPino Jan 23, 2025
7716475
Small Fixes on ML Mobile Net + new VIT processor
DiegoPino Jan 23, 2025
e77466b
Allow a global forced processing config
DiegoPino Jan 23, 2025
7263e09
Fixes region translation between cropped images/ chained processors
DiegoPino Jan 24, 2025
27ac211
wrong logging channel
DiegoPino Jan 24, 2025
c2c20ba
i am tired... i put something on the keyboard while committing!
DiegoPino Jan 24, 2025
375fb1b
Not my best... here fix the region
DiegoPino Jan 24, 2025
b6ad849
What was i thinking?
DiegoPino Jan 26, 2025
766ba3b
Define basic image/input needs to the image models
DiegoPino Jan 29, 2025
adc24f6
Fix comment
DiegoPino Jan 29, 2025
21563db
See if this makes sense (will have to test with data to compare ... s…
DiegoPino Jan 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions config/schema/strawberry_runners.schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ strawberryfield_runners.strawberry_runners_postprocessor.*:
parent:
type: integer
label: 'Parent ID of the Post processor Plugin'

strawberryfield_runners.strawberry_runners_postprocessor.binary:
type: config_object
label: 'Strawberry Runners Post Processor Config Entity Binary specific config'
Expand All @@ -48,7 +47,7 @@ strawberryfield_runners.strawberry_runners_postprocessor.binary:
label: 'Mimetypes(s) to limit this Processor to'
path:
type: string
label: 'The path for he binary to execute'
label: 'The path for the binary to execute'
arguments:
type: string
label: 'Any additional argument your executable binary requires'
Expand All @@ -60,6 +59,12 @@ strawberryfield_runners.strawberry_runners_postprocessor.binary:
label: 'Where and how the output will be used'
sequence:
- type: string
uses_timeout_executable:
type: boolean
label: 'if timeout host binary is to be used to control executable binary timeouts'
timeout_path:
type: string
label: 'The path for the timeout binary to execute'
timeout:
type: integer
label: 'Timeout in seconds for this process'
Expand Down Expand Up @@ -141,6 +146,12 @@ strawberryfield_runners.strawberry_runners_postprocessor.ocr:
processor_queue_type:
type: string
label: 'The queue to use for this processor'
uses_timeout_executable:
type: boolean
label: 'if timeout host binary is to be used to control executable binary timeouts'
timeout_path:
type: string
label: 'The path for the timeout binary to execute'
timeout:
type: integer
label: 'Timeout in seconds for this process'
Expand Down Expand Up @@ -182,6 +193,12 @@ strawberryfield_runners.strawberry_runners_postprocessor.filesequence:
label: 'Where and how the output will be used'
sequence:
- type: string
uses_timeout_executable:
type: boolean
label: 'if timeout host binary is to be used to control executable binary timeouts'
timeout_path:
type: string
label: 'The path for the timeout binary to execute'
timeout:
type: integer
label: 'Timeout in seconds for this process'
Expand Down Expand Up @@ -214,6 +231,12 @@ strawberryfield_runners.strawberry_runners_postprocessor.waczpages:
label: 'Where and how the output will be used'
sequence:
- type: string
uses_timeout_executable:
type: boolean
label: 'if timeout host binary is to be used to control executable binary timeouts'
timeout_path:
type: string
label: 'The path for the timeout binary to execute'
timeout:
type: integer
label: 'Timeout in seconds for this process'
Expand Down Expand Up @@ -246,6 +269,12 @@ strawberryfield_runners.strawberry_runners_postprocessor.webpage:
label: 'Where and how the output will be used'
sequence:
- type: string
uses_timeout_executable:
type: boolean
label: 'if timeout host binary is to be used to control executable binary timeouts'
timeout_path:
type: string
label: 'The path for the timeout binary to execute'
timeout:
type: integer
label: 'Timeout in seconds for this process'
Expand All @@ -264,3 +293,11 @@ strawberryfield_runners.strawberry_runners_postprocessor.webpage:
nlp_method:
type: string
label: 'The NLP method, spaCy or Polyglot'
strawberry_runners.general:
type: config_object
label: General SBR Module settings
mapping:
force_processing:
type: boolean
label: 'When true, any Processor will be forced to run on any ADO change independently of individual configurations. Meant for testing or re-storing wrongly executed processing. Do not enable on production if you do not know what you are doing'
default: false
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Config\Entity\DraggableListBuilder;
use Drupal\Core\Form\FormStateInterface;
use Drupal\strawberry_runners\Entity\strawberryRunnerPostprocessorEntityInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\EntityStorageInterface;
Expand Down Expand Up @@ -106,6 +107,47 @@ public function render() {
return $build;
}

/**
* {@inheritdoc}
*/
public function load() {
$entity_ids = $this->getEntityIds();
/* @var $entities strawberryRunnerPostprocessorEntityInterface[] */
$entities = $this->storage->loadMultipleOverrideFree($entity_ids);

// Sort the entities using the entity class's sort() method.
// See \Drupal\Core\Config\Entity\ConfigEntityBase::sort().
uasort($entities, [$this->entityType->getClass(), 'sort']);
foreach ($entities as $key => $entity) {
$hash[$entity->id()] = $key;
}
$hash_inverse = array_flip($hash);

$hierarchical = [];

foreach ($hash as $entity_id => $original_numeric_id) {
$id_of_parent = $entities[$original_numeric_id]->getParent();
if ($id_of_parent !== '') {
$hierarchical[$hash[$id_of_parent]] = $hierarchical[$hash[$id_of_parent]] ?? [];
$hierarchical[$hash[$id_of_parent]][$hash[$entity_id]] = $hash[$entity_id];
}
else {
$hierarchical[$hash[$entity_id]] = $hierarchical[$hash[$entity_id]] ?? [];
}
}
$added = [];
foreach($hierarchical as $entity_id => $all_children) {
$this->sortTreeByChildren($entity_id, $hierarchical, $added);
}
$added = array_flip($added);
uksort($entities,
function ($a, $b) use ($added) {
return $added[$a] <=> $added[$b];
});

return $entities;
}

public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
$form[$this->entitiesKey]['#tabledrag'][] =
Expand All @@ -125,7 +167,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'group' => 'tabledrag-postprocessor-depth',
'hidden' => TRUE,
];
return $form;
return $form;
}

/**
Expand All @@ -137,8 +179,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
* and inserts the 'edit' and 'delete' links as defined for the entity type.
*/
public function buildHeader() {
$header['Title'] = $this->t('Post ID');
$header['label'] = $this->t('Post Processor Label');
$header['title'] = $this->t('Post Processor Label');
$header['id'] = $this->t('ID');
$header['parent'] = $this->t('Parent');
$header['depth'] = $this->t('Depth');
Expand All @@ -156,24 +197,40 @@ public function buildRow(EntityInterface $entity) {
'#theme' => 'indentation',
'#size' => $entity->getDepth(),
],
'#plain_text' => $entity->id(),
'#plain_text' => $entity->label(),
];
$row['label'] = $entity->label();
$row['id'] = [
'hidden' => [
'#type' => 'hidden',
'#value' => $entity->id(),
'#parents' => [$this->entitiesKey, $entity->id(), 'id'],
'#attributes' => ['class' => ['tabledrag-postprocessor-id']],
],
'text' => [
'#markup' => $entity->id(),
]
];
$row['parent'] = [
'hidden' => [
'#type' => 'hidden',
'#default_value' => $entity->getParent(),
'#parents' => [$this->entitiesKey, $entity->id(), 'parent'],
'#attributes' => ['class' => ['tabledrag-postprocessor-parent']],
],
'text' => [
'#markup' => $entity->getParent(),
]
];
$row['depth'] = [
'hidden' => [
'#type' => 'hidden',
'#default_value' => $entity->getDepth(),
'#parents' => [$this->entitiesKey, $entity->id(), 'depth'],
'#attributes' => ['class' => ['tabledrag-postprocessor-depth']],
],
'text' => [
'#markup' => $entity->getDepth(),
]
];
$row['active'] = $entity->isActive() ? [ '#markup' => $this->t('Yes')] : [ '#markup' =>$this->t('No')];

Expand All @@ -182,7 +239,6 @@ public function buildRow(EntityInterface $entity) {

public function submitForm(array &$form, FormStateInterface $form_state) {
foreach ($form_state->getValue($this->entitiesKey) as $id => $value) {

if (isset($this->entities[$id]) && (
$this->entities[$id]->get($this->weightKey) != $value['weight'] ||
$this->entities[$id]->getDepth() != $value['depth'] ||
Expand All @@ -202,5 +258,36 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state); // TODO: Change the autogenerated stub
}

protected function sortTreeByChildren($row_id, $tree, &$ordered) {
if (isset($tree[$row_id]) && !in_array($row_id, $ordered)) {
$subtree[] = $row_id;
$offset = NULL;
foreach ($tree[$row_id] as $child_id) {
if (in_array($child_id, $ordered)) {
// When a child is found, we don't add it again to the main order.
// Maybe we should delete it?
$child_offset = array_search($child_id, $ordered, TRUE);
// When multiple offsets are present we take the one that inserts the subtree earlier.
if ($offset !== NULL) {
$offset = min($offset, $child_offset);
}
else {
$offset = $child_offset;
}
}
else {
// Only add of course if not there already.
$subtree[] = $child_id;
}
}
if ($offset !== NULL) {
array_splice($ordered, $offset,0, $subtree);
}
else {
$ordered = array_merge($ordered, $subtree);
}
}
}


}
31 changes: 17 additions & 14 deletions src/Entity/strawberryRunnerPostprocessorEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,21 +189,13 @@ public function setPluginconfig(array $pluginconfig): void {
*/
public static function sort(ConfigEntityInterface $a, ConfigEntityInterface $b) {

// Check if the entities are flags, if not go with the default.
if ($a instanceof strawberryRunnerPostprocessorEntityInterface && $b instanceof strawberryRunnerPostprocessorEntityInterface) {

if ($a->isActive() && $b->isActive()) {
return static::hierarchicalSort($a, $b);
}
elseif (!$a->isActive()) {
return -1;
}
elseif (!$b->isActive()) {
return 1;
}
return static::hierarchicalSort($a, $b);
}
else {
return static::sort($a, $b);
}

return parent::sort($a, $b);
}

/**
Expand All @@ -216,17 +208,28 @@ public static function hierarchicalSort(ConfigEntityInterface $a, ConfigEntityIn
$a_weight = isset($a->weight) ? $a->weight : 0;
$b_weight = isset($b->weight) ? $b->weight : 0;
if ($a_parent == $b->id()) {
return 1;
return -1;
}
if ($b_parent == $a->id()) {
return 1;
}
if ($a_parent == '' && $b_parent !== '') {
return 1;
}
if ($a_parent !== '' && $b_parent == '') {
return -1;
}

if ($a_weight == $b_weight) {
$a_label = $a->label();
$b_label = $b->label();
return strnatcasecmp($a_label, $b_label);
}
return ($a_weight < $b_weight) ? -1 : 1;
if ($a->depth != $b->depth) {
return (($a->depth ?? 0) * -1) <=> (($b->depth ?? 0) * -1);
}

return $a_weight <=> $b_weight;
}

}
10 changes: 10 additions & 0 deletions src/Entity/strawberryRunnerPostprocessorEntityInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,14 @@ public function getPluginconfig(): array;
*/
public function setPluginconfig(array $pluginconfig): void;

/**
* @return string
*/
public function getParent(): string;

/**
* @return int
*/
public function getDepth(): int;

}
1 change: 1 addition & 0 deletions src/Plugin/Action/StrawberryRunnersPostProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* @Action(
* id = "entity:sbr_posstprocess_action",
* action_label = @Translation("Trigger Strawberrry Runners process/reprocess for Archipelago Digital Objects"),
* label = @Translation("Trigger Strawberrry Runners process/reprocess for Archipelago Digital Objects"),
* category = @Translation("Strawberry Runners"),
* deriver = "Drupal\strawberry_runners\Plugin\Action\Derivative\EntitySbfActionDeriver",
* type = "node",
Expand Down
Loading