sphenlee / waterwheel

A workflow scheduler based on petri-nets
MIT License
67 stars 10 forks source link

Project deletion fails for projects with jobs #8

Open uint0 opened 2 years ago

uint0 commented 2 years ago

Description

Projects with jobs cannot be deleted. A 500 error is returned as a result of a foreign key constraint violation job_project_id_fkey.

Expected Behavior

Project is deleted or marked inactive. Is it safe to just immediately cascade delete everything out of the database? Could there be issues with inflight / enqueued tasks?

Steps to reproduce

  1. Run the application
  2. Create a project

    $ curl -X POST -H 'Content-Type: application/json' -d @sample/project.json localhost:8080/api/projects -i
    HTTP/1.1 201 Created
    content-type: application/json
    content-length: 150
    date: Sat, 19 Mar 2022 10:00:58 GMT
    
    {"uuid":"4fb168e4-b963-431d-85b6-ac108542c036","name":"test_project","description":"This is a sample project to demonstrate Waterwheel","config":null}
  3. Create a job in the project

    $ curl -X POST -H 'Content-Type: application/json' -d @sample/jobs/simple.json localhost:8080/api/jobs -i
    HTTP/1.1 201 Created
    content-length: 0
    date: Sat, 19 Mar 2022 10:02:37 GMT
    
    $ curl -i localhost:8080/api/projects/4fb168e4-b963-431d-85b6-ac108542c036/jobs
    HTTP/1.1 200 OK
    content-type: application/json
    content-length: 209
    date: Sat, 19 Mar 2022 10:03:50 GMT
    
    [{"job_id":"51c35e5d-e777-4797-b91b-2526bd4bafdc","name":"simple_job","description":"a simple job to test that waterwheel is working","paused":false,"success":78,"running":0,"failure":0,"waiting":0,"error":0}]
  4. Delete the associated project
    $ curl -i -X DELETE localhost:8080/api/projects/4fb168e4-b963-431d-85b6-ac108542c036
    HTTP/1.1 500 Internal Server Error
    content-length: 0
    date: Sat, 19 Mar 2022 10:04:38 GMT

Logs

[2022-03-19T21:04:38.873+11:00 WARN waterwheel::server::api::project]
error deleting project: update or delete on table "project" violates foreign key constraint "job_project_id_fkey" on table "job"
[2022-03-19T21:04:38.873+11:00 ERROR highnoon::filter::log]
response
    method: DELETE
    uri: /api/projects/4fb168e4-b963-431d-85b6-ac108542c036
    status: 500 Internal Server Error
sphenlee commented 2 years ago

Currently all deletions fail because of constraint violations. I don't think we want to cascade delete here, it seems valuable to mark deleted objects as inactive but retain them in the database for history.