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

[automation] ScriptFileWatcher Initial import now only processes dir #2708

Merged
merged 1 commit into from
Jan 29, 2022

Conversation

jpg0
Copy link
Contributor

@jpg0 jpg0 commented Jan 25, 2022

ScriptFileWatcher reused logic for recursion and initial import. Initial import always processes a directory and it's contents (only), whereas ongoing monitoring may choose not to descend into subdirs, and processes files too. This change separates the logic.

Signed-off-by: Jonathan Gilbert jpg@trillica.com

Signed-off-by: Jonathan Gilbert <jpg@trillica.com>
@jpg0 jpg0 requested a review from a team as a code owner January 25, 2022 15:11
@jpg0
Copy link
Contributor Author

jpg0 commented Jan 25, 2022

@digitaldan would you be able to test this? I seemed to be working for me, but I've had a few issues with deployment and wanted a second check if possible. Thanks (oh - it fixes the initial import upon startup problem).

@cweitkamp cweitkamp added automation bug An unexpected problem or unintended behavior of the Core labels Jan 26, 2022
@digitaldan
Copy link
Contributor

Just gave it a try, and yes this does indeed fix the issue, thanks!

Copy link
Contributor

@digitaldan digitaldan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@cweitkamp cweitkamp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for the fix.

@cweitkamp cweitkamp merged commit 290ad08 into openhab:main Jan 29, 2022
@cweitkamp cweitkamp added this to the 3.3 milestone Jan 29, 2022
@@ -285,7 +303,7 @@ private synchronized void onStartLevelChanged(int newLevel) {
if (newLevel >= StartLevelService.STARTLEVEL_MODEL) { // start
ScheduledExecutorService localScheduler = executorFactory.get();
scheduler = localScheduler;
localScheduler.submit(() -> importResources(new File(pathToWatch)));
localScheduler.submit(() -> importInitialResources(new File(pathToWatch)));
localScheduler.scheduleWithFixedDelay(() -> checkFiles(currentStartLevel), 0, RECHECK_INTERVAL,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could it be that the missing initial delay causes the issues mentioned in #2727? If you do not import everything in the line above, and start this without any delay it could be that something is missing when checkFiles is called for the first time and therefore something is removed from pending too early or not removed from pending and therefore ignored in later checks?

Otherwise I don't see how this change could result in something not being loaded, except it runs into something like #2466, which worked before because it was loaded on startup?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding this change specifically, the only effective logic change is that at startup directories are not recursively scanned iff watchSubDirectories() returns false. If it is set to true, then the behaviour should be identical.

As for whether there is a race happening somewhere between both of these import processes (importInitialResources and checkFiles), this could indeed be the case, but should not have changed as a result of this PR. However, now that there is an explicit importInitialResources, it would be possible to synchronize (on pending) as part of this method, plus even (optionally) move the scheduling of checkFiles into that method. By adding the synchronisation in importInitialResources, then checkFiles will need to wait for it to complete entirely before it can run.

(tbh I believe that this class needs a rewrite, and would personally make it abstract and push the responsibility of creating the osgi components to language implementations rather than having a combined all-language watcher. I pulled JS out of this into the JS plugin, but didn't want to take on doing if for the other languages.)

splatch pushed a commit to ConnectorIO/copybara-hab-core that referenced this pull request Jul 12, 2023
…penhab#2708)

Signed-off-by: Jonathan Gilbert <jpg@trillica.com>
GitOrigin-RevId: 290ad08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automation bug An unexpected problem or unintended behavior of the Core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants