Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

views: define signals for view methods #171

Open
slint opened this issue Nov 24, 2017 · 0 comments
Open

views: define signals for view methods #171

slint opened this issue Nov 24, 2017 · 0 comments
Milestone

Comments

@slint
Copy link
Member

slint commented Nov 24, 2017

At the moment, there is no official way to perform any actions before or after a record REST API request (or to be more precise, after a record CRUD operation has been committed to the database).

Sending signals at the end of each REST resource method would be a solution to this problem, and allow for such pluggable actions. The end result would be something like after_records_post, after_record_put, after_record_delete, etc.

The ugly part

Although this might be frowned upon since it's introducing the danger of a user of the module modifying the database state or creating side effects, it's a logical use case for when there is a need for sequential execution of actions. A common example is record indexing, where a created/modified/deleted record should be sent for the appropriate indexing operation on ElasticSearch, in order to appear or be removed from the search results. This would prevent the following pattern from happening:

  1. POST /api/records
    • DB transaction started
      • Payload validated
      • Record with PID recid:1 created in transaction
      • Record sent for indexing
    • DB commit fails
  2. GET /api/records
    • Record with PID recid:1 available in results
  3. GET /api/records/1
    • 404 Not found

(Another issue is the fact that signals have proven to be hard to debug, especially in complex operations (eg. deposit actions), so introducing more of them won't make things easier... This though is general issue that might need better handling on a global level, such as better documentation of signals or keeping a programmatically accessible registry of signals for debugging purposes)

@lnielsen lnielsen added this to the someday milestone Mar 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants