e-oj / Fawn

Transactions for MongoDB (See the README)
https://www.npmjs.com/package/fawn
MIT License
485 stars 54 forks source link

ojlinttaskcollections collection auto-drop after task #61

Closed orassayag closed 6 years ago

orassayag commented 6 years ago

I needed to drop it manually after each task i preformed. Can you preform an action that drops it each task? Thanks!

e-oj commented 6 years ago
  1. You don't want to drop the whole collection at the end of each individual task because other tasks could still be running elsewhere in the app.

  2. Currently, when a task is done, it gets deleted from the collection; if all your tasks are successful, ojlinttaskcollections will be empty and would take up zero memory. However, if a task fails halfway through, and you delete the whole collection, there would be no way to rollback to a stable state . The roller uses the task collection to rollback unfinished tasks.

  3. The only time it's safe to drop the whole collection is when your server is shutting down. Even then, you should check to make sure that the collection is empty before dropping it. The point of having a task collection is to make sure that even if the server crashes, there is a persistent source of truth from which rollbacks can be performed.

TLDR; You shouldn't delete the whole collection at the end of every task, unless you're using the task in only one area of the app and you shouldn't delete the collection when the server shuts down, unless you're sure it's completely empty.

orassayag commented 6 years ago

You're right. my bad, didn't think about that.