immich icon indicating copy to clipboard operation
immich copied to clipboard

feat(server): support simple webhook

Open panoti opened this issue 3 years ago • 13 comments

Webhook can help everybody can trigger a zapier, n8n pipline easier. We can implement some external tasks (eg: Geolocation interpolation, Face recognization) as plugins/addons by using webhook.

  • [x] Remove hard-code http://immich-machine-learning:3003/image-classifier/tag-image and http://immich-machine-learning:3003/object-detection/detect-object away from worker service. Machine learning service is standalone now. Everyone can launch it only when necessary.
  • [x] Create webhook interface POST <WEBHOOK_URL> with payload:
{
  "type": "AssetCreationEvent",
  "asset": {
    "id": "assetId",
    ...
  }
}
  • [x] Create api POST /webhook on ml service to received webhook request from immich server.

panoti avatar Sep 05 '22 11:09 panoti

Is this PR for moving the rest api invoked from the server to pub/sub?

alextran1502 avatar Sep 05 '22 12:09 alextran1502

Is this PR for moving the rest api invoked from the server to pub/sub?

Only for machine learning service. Api service can communicate with machine learning service by using Redis broker. I found that machine learning service is optional. Throwing error maybe not good technically in the case of service not available.

panoti avatar Sep 05 '22 13:09 panoti

Is this PR for moving the rest api invoked from the server to pub/sub?

Only for machine learning service. Api service can communicate with machine learning service by using Redis broker.

The communication between the server/microservices and the machine learning containers is intentionally designed to use REST apis so that people with their own custom model can make a simple web server as a drop in replacement for either object detection or image classification

alextran1502 avatar Sep 05 '22 13:09 alextran1502

The communication between the server/microservices and the machine learning containers is intentionally designed to use REST apis so that people with their own customs model can make a simple web server as a drop in replacement for either object detection or image classification

I found that machine learning service is optional. Throwing error maybe not good technically in the case of service not available. User can customs their model easily without changes as well , just need to start the machine learning service. Machine learning service listen event from broker and don't care about API or microservice service. The current implementation, you can see microservice depend on machine learning service address when create http request. For dockerless installation, users need to address their machine learning service location, someone had to modify their host file.

panoti avatar Sep 05 '22 13:09 panoti

The communication between the server/microservices and the machine learning containers is intentionally designed to use REST apis so that people with their own custom model can make a simple web server as a drop in replacement for either object detection or image classification

If users wanna custom machine learning service in other programming language like python, R, ... I think they also use redis pub/sub easier. Of course, REST interface would be simpler, but I don't want the worker service to be dependent on other service addresses.

panoti avatar Sep 05 '22 13:09 panoti

I prefer simplicity in this matter.

alextran1502 avatar Sep 05 '22 13:09 alextran1502

I prefer simplicity in this matter.

I have a thought about webhook. I will move to webhook approach.

panoti avatar Sep 05 '22 13:09 panoti

What are you trying to accomplish with this PR?

My goal for the drop-in replacement is for the user spin up their web server that runs their ML model. Then from Immich's side, we make an environment variable for the current hard-coded endpoint that is now the machine learning container's DNS, and then the job should be done.

alextran1502 avatar Sep 05 '22 14:09 alextran1502

What are you trying to accomplish with this PR?

My goal for the drop-in replacement is for the user spin up their web server that runs their ML model. Then from Immich's side, we make an environment variable for the current hard-coded endpoint that is now the machine learning container's DNS, and then the job should be done.

My goals are:

  1. Remove dependency between worker service and machine learning service.
  2. Create a general-purpose method to hook asset creation/deletion/... events so that we can trigger a workflow/pipeline for other tasks (like ML job, my custom n8n workflow, ...)

panoti avatar Sep 05 '22 14:09 panoti

n8n workflow can receive messages from redis pub/sub, so I think using redis pub/sub is general-purpose method. But you said that REST api is simpler with env var, then I think we can create WEBHOOK_URL var for your goals. That's all. There is no conflict with both your goals and my goals.

panoti avatar Sep 05 '22 14:09 panoti

n8n workflow can receive messages from redis pub/sub, so I think using redis pub/sub is general-purpose method. But you said that REST api id simpler with env var. I think we can create WEBHOOK_URL var for your goals. That's all. There is no conflict with both your goals and my goals.

Sounds good! Let's go with the webhook approach

alextran1502 avatar Sep 05 '22 14:09 alextran1502

Is this PR still alive, or can/should it be closed?

bo0tzz avatar Nov 17 '22 20:11 bo0tzz

I like this feature, and I would like to keep this PR open as a reminder of how to do it in the future

alextran1502 avatar Nov 20 '22 22:11 alextran1502