Skip to content

Commit

Permalink
refactor: tweak defaults and add tagging adhoc task spawn limit
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewhilton committed Oct 22, 2024
1 parent 82ff8c0 commit c6601ae
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
19 changes: 13 additions & 6 deletions classes/task/trigger_update_object_tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,18 @@ public function get_name() {
* Execute task
*/
public function execute() {
// Queue adhoc task, nothing else.
$task = new update_object_tags();
$task->set_custom_data([
'iteration' => 1,
]);
manager::queue_adhoc_task($task, true);
// Only schedule up to the max amount, less any that are already scheduled.
$alreadyexist = count(manager::get_adhoc_tasks(update_object_tags::class));
$maxtoschedule = get_config('tool_objectfs', 'maxtaggingtaskstospawn');
$toschedule = max(0, $maxtoschedule - $alreadyexist);

for($i = 0; $i < $toschedule; $i++) {
// Queue adhoc task, nothing else.
$task = new update_object_tags();
$task->set_custom_data([
'iteration' => 1,
]);
manager::queue_adhoc_task($task);
}
}
}
2 changes: 2 additions & 0 deletions lang/en/tool_objectfs.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@
$string['settings:maxtaggingperrun:desc'] = 'The maximum number of objects to sync tags for per tagging sync adhoc task iteration.';
$string['settings:maxtaggingiterations'] = 'Object tagging adhoc sync maximum number of iterations ';
$string['settings:maxtaggingiterations:desc'] = 'The maximum number of times the tagging sync adhoc task will requeue itself. To avoid accidental infinite runaway.';
$string['settings:maxtaggingtaskstospawn'] = 'Maximum number of parallel tagging migration tasks';
$string['settings:maxtaggingtaskstospawn:desc'] = 'Each trigger of the scheduled task `trigger_update_object_tags` will spawn this amount of tasks, minus those that are already running.';
$string['settings:overrideobjecttags'] = 'Allow object tag override';
$string['settings:overrideobjecttags:desc'] = 'Allows ObjectFS to overwrite tags on objects that already exist in the external store. If not checked, objectfs will only set tags when the objects "environment" value is empty or is the same as currently defined.';
$string['settings:tagsources'] = 'Tag sources';
Expand Down
11 changes: 9 additions & 2 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,21 @@
$settings->add(new admin_setting_configtext('tool_objectfs/maxtaggingperrun',
new lang_string('settings:maxtaggingperrun', 'tool_objectfs'),
get_string('settings:maxtaggingperrun:desc', 'tool_objectfs'),
10000,
1000,
PARAM_INT
));

$settings->add(new admin_setting_configtext('tool_objectfs/maxtaggingiterations',
new lang_string('settings:maxtaggingiterations', 'tool_objectfs'),
get_string('settings:maxtaggingiterations:desc', 'tool_objectfs'),
1000,
10000,
PARAM_INT
));

$settings->add(new admin_setting_configtext('tool_objectfs/maxtaggingtaskstospawn',
new lang_string('settings:maxtaggingtaskstospawn', 'tool_objectfs'),
get_string('settings:maxtaggingtaskstospawn:desc', 'tool_objectfs'),
1,
PARAM_INT
));

Expand Down
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2021122310; // The current plugin version (Date: YYYYMMDDXX).
$plugin->release = 2021122310; // Same as version.
$plugin->version = 2021122311; // The current plugin version (Date: YYYYMMDDXX).
$plugin->release = 2021122311; // Same as version.
$plugin->requires = 2013111811; // Requires Filesystem API.
$plugin->component = "tool_objectfs";
$plugin->maturity = MATURITY_STABLE;
Expand Down

0 comments on commit c6601ae

Please sign in to comment.