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

feat(server): Automatic watching of library folders #6192

Merged
merged 105 commits into from
Jan 31, 2024
Merged

Conversation

etnoy
Copy link
Contributor

@etnoy etnoy commented Jan 5, 2024

  • Adds chokidar to monitor external library folders
  • Adds library watch configuration via config file and web UI
  • Filters watched files by file extension
  • Checks for added, changed, and deleted files
  • Allows the configuration of chokidar parameters via config file (polling true/false, polling interval, stability threshold etc.)
  • Plenty of unit and e2e tests

image

image

Performance is still an unknown. I suggest we merge this and let daring users enable the watcher config flag and report back.

@etnoy etnoy added 🗄️server external-library Issues related to external libraries labels Jan 5, 2024
Copy link

cloudflare-pages bot commented Jan 5, 2024

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: aff0810
Status: ✅  Deploy successful!
Preview URL: https://71bdc3eb.immich.pages.dev
Branch Preview URL: https://feat-library-watching.immich.pages.dev

View logs

Copy link
Member

@bo0tzz bo0tzz left a comment

Choose a reason for hiding this comment

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

Does this implementation have a way to remove the watcher for a library without restarting the container?

How will the file watching behave when it's running in multiple containers simultaneously?

server/src/domain/library/library.service.ts Outdated Show resolved Hide resolved
server/src/domain/library/library.service.ts Outdated Show resolved Hide resolved
server/src/domain/system-config/system-config.core.ts Outdated Show resolved Hide resolved
@etnoy
Copy link
Contributor Author

etnoy commented Jan 5, 2024

Does this implementation have a way to remove the watcher for a library without restarting the container?

How will the file watching behave when it's running in multiple containers simultaneously?

It's just a draft still, much work left to be done. I wanted the GitHub actions tests to run

@alextran1502
Copy link
Contributor

What happens if the external library gets unmounted?

@etnoy
Copy link
Contributor Author

etnoy commented Jan 29, 2024

What happens if the external library gets unmounted?

I tried, and it sent file deletion events for all files that are now missing. The files then become offline

@etnoy etnoy enabled auto-merge (squash) January 30, 2024 23:47
@etnoy etnoy merged commit 068e703 into main Jan 31, 2024
24 checks passed
@etnoy etnoy deleted the feat/library-watching branch January 31, 2024 08:15
@nodis
Copy link

nodis commented Feb 1, 2024

Hello, I upgraded to 1.94.1 and enabled “Automatic library watching (experimental)”, but the following error occurred:

[Nest] 7  - 02/01/2024, 3:51:28 AM   ERROR [LibraryService] Library watcher for library c69faf55-f96d-4aa0-b83b-2d80cbc27d98 encountered error: Error: ENOSPC: System limit for number of file watchers reached, watch '/media/volume1/homes/nodis/Photos/MobileBackup/Mi 10 Pro/DCIM/Screenshots/@eaDir/Screenshot_2015-12-25-23-41-06_com.excelliance.dualaid.png'
2024/02/01
11:51:28
[Nest] 7  - 02/01/2024, 3:51:28 AM   ERROR [LibraryService] Library watcher for library c69faf55-f96d-4aa0-b83b-2d80cbc27d98 encountered error: Error: ENOSPC: System limit for number of file watchers reached, watch '/media/volume1/homes/nodis/Photos/MobileBackup/Mi 10 Pro/DCIM/Screenshots/@eaDir/Screenshot_2015-12-25-23-41-08_com.excelliance.dualaid.jpg'
2024/02/01
11:51:28
[Nest] 7  - 02/01/2024, 3:51:28 AM   ERROR [LibraryService] Library watcher for library c69faf55-f96d-4aa0-b83b-2d80cbc27d98 encountered error: Error: ENOSPC: System limit for number of file watchers reached, watch '/media/volume1/homes/nodis/Photos/MobileBackup/Mi 10 Pro/DCIM/Screenshots/@eaDir/Screenshot_2015-12-25-23-41-06_com_1457834466869.excelliance.dualaid.png'
2024/02/01
11:51:28
[Nest] 7  - 02/01/2024, 3:51:28 AM   ERROR [LibraryService] Library watcher for library c69faf55-f96d-4aa0-b83b-2d80cbc27d98 encountered error: Error: ENOSPC: System limit for number of file watchers reached, watch '/media/volume1/homes/nodis/Photos/MobileBackup/Mi 10 Pro/DCIM/Screenshots/@eaDir/Screenshot_2015-12-25-23-41-08_com_1457834467052.excelliance.dualaid.png'
2024/02/01
11:51:28
[Nest] 7  - 02/01/2024, 3:51:28 AM   ERROR [LibraryService] Library watcher for library c69faf55-f96d-4aa0-b83b-2d80cbc27d98 encountered error: Error: ENOSPC: System limit for number of file watchers reached, watch '/media/volume1/homes/nodis/Photos/MobileBackup/Mi 10 Pro/DCIM/Screenshots/@eaDir/Screenshot_2015-12-25-23-42-24_com.excelliance.dualaid.png'

@alextran1502
Copy link
Contributor

@nodis
Copy link

nodis commented Feb 1, 2024

@nodis
Copy link

nodis commented Feb 1, 2024

@nodis you can fix your system with this https://stackoverflow.com/questions/55763428/react-native-error-enospc-system-limit-for-number-of-file-watchers-reached

@alextran1502 hello,I followed the instructions and added a line to the sysctl. conf file: "fs.inotify.max_user_watches=524288"
The "immich" web homepage cannot be opened, displaying "502 Bad Gateway",
The error log for container "immich_server" is as follows:

[Nest] 7  - 02/01/2024, 8:25:57 AM     LOG [NestFactory] Starting Nest application...
[Nest] 7  - 02/01/2024, 8:25:57 AM     LOG [InstanceLoader] TypeOrmModule dependencies initialized +39ms
[Nest] 7  - 02/01/2024, 8:25:57 AM   ERROR [TypeOrmModule] Unable to connect to the database. Retrying (1)...
Error: connect ECONNREFUSED 172.21.0.5:5432
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1595:16)

[Nest] 7  - 02/01/2024, 8:25:57 AM   ERROR [TypeOrmModule] Unable to connect to the database. Retrying (2)...
Error: connect ECONNREFUSED 172.21.0.5:5432
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1595:16)
[Nest] 7  - 02/01/2024, 8:25:57 AM   ERROR [TypeOrmModule] Unable to connect to the database. Retrying (3)...
Error: connect ECONNREFUSED 172.21.0.5:5432
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1595:16)
[Nest] 7  - 02/01/2024, 8:25:57 AM   ERROR [TypeOrmModule] Unable to connect to the database. Retrying (4)...
Error: connect ECONNREFUSED 172.21.0.5:5432
[Nest] 7  - 02/01/2024, 8:25:57 AM     LOG [InstanceLoader] BullModule dependencies initialized +0ms
[Nest] 7  - 02/01/2024, 8:25:57 AM     LOG [InstanceLoader] ConfigHostModule dependencies initialized +0ms
[Nest] 7  - 02/01/2024, 8:25:57 AM     LOG [InstanceLoader] DiscoveryModule dependencies initialized +0ms
[Nest] 7  - 02/01/2024, 8:25:57 AM     LOG [InstanceLoader] ScheduleModule dependencies initialized +0ms
[Nest] 7  - 02/01/2024, 8:25:57 AM     LOG [InstanceLoader] ConfigModule dependencies initialized +0ms
[Nest] 7  - 02/01/2024, 8:25:57 AM     LOG [InstanceLoader] BullModule dependencies initialized +0ms
[Nest] 7  - 02/01/2024, 8:25:57 AM     LOG [InstanceLoader] ScheduleModule dependencies initialized +0ms
[Nest] 7  - 02/01/2024, 8:25:57 AM     LOG [InstanceLoader] BullModule dependencies initialized +0ms
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1595:16)
[Nest] 7  - 02/01/2024, 8:25:57 AM   ERROR [TypeOrmModule] Unable to connect to the database. Retrying (5)...
Error: connect ECONNREFUSED 172.21.0.5:5432
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1595:16)
[Nest] 7  - 02/01/2024, 8:25:57 AM   ERROR [TypeOrmModule] Unable to connect to the database. Retrying (6)...
Error: connect ECONNREFUSED 172.21.0.5:5432
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1595:16)
[Nest] 7  - 02/01/2024, 8:25:57 AM   ERROR [TypeOrmModule] Unable to connect to the database. Retrying (7)...
Error: connect ECONNREFUSED 172.21.0.5:5432
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1595:16)
[Nest] 7  - 02/01/2024, 8:25:57 AM   ERROR [TypeOrmModule] Unable to connect to the database. Retrying (8)...
Error: connect ECONNREFUSED 172.21.0.5:5432
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1595:16)
[Nest] 7  - 02/01/2024, 8:25:57 AM   ERROR [TypeOrmModule] Unable to connect to the database. Retrying (9)...
Error: connect ECONNREFUSED 172.21.0.5:5432
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1595:16)
[Nest] 7  - 02/01/2024, 8:25:57 AM   ERROR [ExceptionHandler] connect ECONNREFUSED 172.21.0.5:5432
Error: connect ECONNREFUSED 172.21.0.5:5432
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1595:16)
[Nest] 7  - 02/01/2024, 8:30:41 AM     LOG [SystemConfigService] LogLevel=log (set via system config)
[Nest] 7  - 02/01/2024, 8:30:49 AM     LOG [LibraryService] Starting to watch library 8b05f464-3703-4834-a886-89d97f1bbdda with import path(s) /media/volume2/photo
[Nest] 7  - 02/01/2024, 8:49:33 AM     LOG [SystemConfigService] LogLevel=log (set via system config)
[Nest] 7  - 02/01/2024, 8:49:35 AM     LOG [LibraryService] Starting to watch library 8b05f464-3703-4834-a886-89d97f1bbdda with import path(s) /media/volume2/photo
/usr/src/app/node_modules/pg-pool/index.js:205
        response.callback(new Error('timeout exceeded when trying to connect'))

                          ^
Error: timeout exceeded when trying to connect
    at Timeout._onTimeout (/usr/src/app/node_modules/pg-pool/index.js:205:27)
    at listOnTimeout (node:internal/timers:573:17)
    at process.processTimers (node:internal/timers:514:7)

Node.js v20.11.0

[Nest] 7  - 02/01/2024, 8:56:06 AM     LOG [SystemConfigService] LogLevel=log (set via system config)
[Nest] 7  - 02/01/2024, 8:56:06 AM     LOG [LibraryService] Starting to watch library 8b05f464-3703-4834-a886-89d97f1bbdda with import path(s) /media/volume2/photo

@danieldietzler
Copy link
Member

@nodis Your database isn't running. Can you double check that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external-library Issues related to external libraries 🗄️server
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants