Skip to content

Conversation

panaaj
Copy link
Member

@panaaj panaaj commented Sep 27, 2024

This PR adds a file watcher to charts folders to detect new files placed in the folder. This makes the new charts available to subsequent requests without having to restart the plugin (#28).

Removing the use of a shared path aligns better with multi-provider support.
Tile paths have a fully qualified path, remove use of relative path.
@panaaj panaaj added enhancement New feature or request feature labels Sep 27, 2024
@panaaj panaaj changed the title Mapbox Style support WIP: Mapbox Style support Sep 27, 2024
@panaaj panaaj requested review from tkurki and sbender9 October 2, 2024 06:46
@panaaj panaaj changed the title WIP: Mapbox Style support Add Mapbox Style support Oct 2, 2024
@panaaj panaaj changed the title Add Mapbox Style support Add File watcher and Mapbox Style support Nov 30, 2024
@panaaj
Copy link
Member Author

panaaj commented Nov 30, 2024

@tkurki Can you please review and if all is OK it's good to publish.

This code seemed to solve Freeboard-SK issue SignalK/freeboard-sk#211

const refreshProviders = async () => {
const td = Date.now() - (lastWatchEvent as number)
app.debug(`last watch event time elapsed = ${td}`)
if (lastWatchEvent && td > 5000) {
Copy link
Member

Choose a reason for hiding this comment

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

Did I understand the logic correctly: if we notice a change in some chart data we reload the chart data the first time the data is needed after 5 seconds of the change?

Could we not just mark the data as stale and when it is next needed reload it? Or always reload when a change is noticed? Why the 5 second delay?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is due to the way FSWatcher produces events and the ability to distinguish when a:

  1. New file is created
  2. An exisiting file is replaced
  3. An existing file is renamed
  4. Multiple files are being added / deleted

There are multiple events produced during a simple file rename with no discernable metadata to indicate the actual operation taking place.... so the delay is to ensure the stream of events has ceased to indicate the process has completed.
Without it we would trigger multiple reloads while a rename, etc. is in process and throw exceptions.

README.md Outdated
@@ -2,7 +2,14 @@

Signal K Node server plugin to provide chart metadata, such as name, description and location of the actual chart tile data.

Supports both v1 and v2 Signal K resources api paths.
Chart metadata is derived from the following supported chart files:
- Mapbox Tiles _(.mbtiles)_
Copy link
Member

Choose a reason for hiding this comment

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

Afaik MBTiles is better known as just MBTiles and touted as open format. The spec README never mentions Mapbox, while it is under their Github org.

We could link to the canonical resources?

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated to MBTiles.
Which canonical resources are you refferring to?

@tkurki
Copy link
Member

tkurki commented Jan 5, 2025

Unrelated to this PR: README is not very consistent

  • default location repeated
  • the steps-oriented configuration instructions are not very universal: some people will use online charts, others mbtiles etc

@msallin
Copy link

msallin commented May 4, 2025

I arrived here because I would like to have two things: 1. the file watcher, and 2. support for recursive folders.
I've a share with a folder called "charts," which contains subfolders with regions. Those subfolders contain multiple different charts for each region.

For a new region, I have to create the folder on the share, add it to the plugin, and restart for every chart I add.

This PR implements the watcher. WDYT about letting the user specify recursive paths?

@panaaj panaaj changed the title Add File watcher and Mapbox Style support Add File watcher support Jul 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants