Supported only on Windows
DirWatcher is long running background time looped scheduled task which exposes the results via REST API. This has two main components:
- REST API Server
- scheduled backuground task
- Golang
- Gin for API Server
- Sqlite database
Application starter is responsible for starting the Process Handler and REST API Server.
Process Handler is responsible for:
- Starting File Watcher
- Starting Cron Job Scheduler
- Registering watcher for file_watcher and cron_job_scheduler config file to notify the respective components.
File Watcher is responsible for:
- Listning for registered events on the configured watch directory.
- Record the event in the file_event database.
Cron Job Scheduler is responsible for:
- Starting Cron Job according to the configuration.
- Record "start_time", "end_time", "total_run_time", "files_added", "files_removed", "magic_string_count" in the job_run database.
REST API Server is responsible for starting and configuruing the Gin HTTP Server.
- id is the primary key
- deleted_files_count is the number of files deleted after the previous cron job run.
- created_files_count is the number of created files after the previous cron job run.
- run_id is the primary key
- job_type is the type of job
- 1 - cron job
- start_time is start the time of the job run
- end_time is the end time of the job run
- status is the current status of the job run
- 1 - in-progress
- 2 - failed
- 3 - completed
- details is the job_type specific details in json format
- job_type 1: magicStringCount, deletedFilesCount, createdFilesCount
NOTE: This file should named as "config.general.windows.json" and should be present in ${programdata}\DirWatcher\ directory.
{
"service": {
"name": "DirWatcher",
"version": "v1.0",
"fileEventDB":{
"dbPath": "<path to file_event.sqlite>",
"initScript": "<path to file_event.sql>"
},
"jobRunsDB":{
"dbPath": "<path to job_runs.sqlite>",
"initScript": "<path to job_runs.sql>"
},
"server": {
"port": "8000",
"allowedOrigins": ["*"],
"allowedMethods": ["GET", "PUT"],
"allowedHeaders": ["Authorization", "Content-Type", "Origin", "ResponseType"]
},
"logging":{
"path":"dirwatcher.log"
}
}
}
service.name is the name of the service.
service.version is the version of the service.
service.fileEventDB.dpPath is the path to the file_event.sqlite file (if the .sqlite file does not exist then the application will create it in the provided path). service.fileEventDB.initScript is the path to the file_event.sql file.
service.jobRunsDB.dpPath is the path to the job_runs.sqlite file (if the .sqlite file does not exist then the application will create it in the provided path), service.jobRunsDB.initScript is the path to the job_runs.sql file.
service.server.port is the port of the REST API server. service.server.allowedOrigins are the list of allowed origins. service.server.allowedMethods are the list of allowed methods. service.server.allowedHeaders is the list of allowed headers.
service.logging.path is the path to the log file.
NOTE: This file should named as "config.filewatcher.windows.json" and should be present in ${programdata}\DirWatcher\ directory.
{
"dirOrFileToWatch": "<path to file or folder to be watched>",
"frequencyInSecond": <pooling ferquency to check for file events in seconds>
}
dirOrFileToWatch is path to file or folder to be watched.
frequencyInSecond is the pooling ferquency to check for file events in seconds
NOTE: This file should named as "config.jobscheduler.windows.json" and should be present in ${programdata}\DirWatcher\ directory.
{
"cronExpression": "<valid cron expression>",
"magicString": "<magic string>"
}
cronExpression is the cron expression (provide the expression in such a way that not more then 1 cron job is running at a given point of time to ensure consistent and accurate results. size should provided considring the size and number of files being watched).
magicString is the magic string to be scanned in the files being watched.
Run the command from the root of the project
go run cmd/main.go
- Supports only windows OS.
- Only add and remove file events are supported. File events like rename, move etc are not supported.
- Does not perform strict validation on config files
- Add autentication and authorization to REST APIs.
- Provide APIs:
- to get more details job run.
- manually start and stop jobs.