Skip to content

#16 webhooks #22

Merged
merged 7 commits into from
Jan 29, 2022
Merged

#16 webhooks #22

merged 7 commits into from
Jan 29, 2022

Conversation

pan261
Copy link
Contributor

@pan261 pan261 commented Jan 28, 2022

Since we are no longer polling for data, there are several architecture changes being made:

  1. The taskRunner is now obsolete, all events are now sent to and handled by the server
  2. The server is responsible for managing the webhooks, as well as the downloader
  3. There is now only one docker container being used, just for the server
    • previously there was a taskRunner instance for each subfolder (x4), now the webhook is registered for the parent folder, all events in the subfolders will be caught
  4. We will use ngrok (for now) to give us a reverse proxy and public url for the webhooks api to talk to the server

All of the old files are in /src/old

Webhook lifecyle management:

  1. After the user authenticates through the server, the webhook setupHooks() function will be called
  2. This setup function will
    • check the webhook callback url configured in the .env file, and if it is not correct, then it will register new webhooks and delete the old ones.
    • if any of the webhooks are inactive, update them to active.
  3. After the setupHooks() function runs, there will be 3 active registered webhooks, one for each of the following events:
    • file added
    • file modified
    • file deleted

Webhook tokens

Webhook tokens are also configured in the .env file, and their lifecycle is as follows:

  1. After the user authenticates through the server, the webhook setupToken() function will be called
  2. This function checks will create a webhook token, or return a message if the token already exists

This function only runs once, and once a webhook token is registered, it doesn't need to be changed. There is an update function for it, but I'm not sure how to incorporate that as of now.

Notes:

There are new npm scripts I made for making running the project easier. Specifically:

  1. npm run start:ngrok will start the ngrok process
  2. npm run build:docker will copy the ngrok url into the .env file, compile the typescript, then build with docker-compose
  3. npm run build will do everything the the previous command will but also opens a webpage at localhost:3000/auth

Make sure you start up ngrok before running any of the docker commands, and you can leave it as a process in the background.


closes #16

@pan261 pan261 requested a review from will1742 January 28, 2022 23:23
@pan261 pan261 merged commit a148ac1 into master Jan 29, 2022
@will1742 will1742 deleted the #16-watcher2.0 branch February 2, 2022 20:52
Sign in to join this conversation on GitHub.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Watcher 2.0 with WebHooks API
1 participant