Skip to content

Syncing afterSave/afterDelete trigger calls (Issue #2489) #2499

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

Merged
merged 4 commits into from
Aug 17, 2016

Conversation

cipiripper
Copy link
Contributor

Implemented syncing afterSave/afterDelete trigger calls with REST request execution flow (Issue 2489). After this change, afterSave and afterDelete triggers CAN return a promise, which needs to be resolved inside a trigger for REST request flow to continue. If trigger doesn't return a promise, request flow continues.

…uest execution flow (Issue 2489). After this change, afterSave and afterDelete triggers CAN return a promise, which needs to be resolved inside a trigger for REST request flow to continue. If trigger doesn't return a promise, request flow continues.
//so trigger execution is synced with RestWrite.execute() call.
//If triggers do not return a promise, they can run async code parallel to the RestWrite.execute() call.
var triggerPromise = trigger(request, response);
if((triggerType === Types.afterSave || triggerType === Types.afterDelete) && triggerPromise && typeof triggerPromise.then === "function")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add { around multi line if please.

@codecov-io
Copy link

codecov-io commented Aug 11, 2016

Current coverage is 91.92% (diff: 100%)

Merging #2499 into master will decrease coverage by 0.54%

@@             master      #2499   diff @@
==========================================
  Files            93         96     +3   
  Lines         10629      10892   +263   
  Methods        1310       1345    +35   
  Messages          0          0          
  Branches       1728       1759    +31   
==========================================
+ Hits           9829      10013   +184   
- Misses          800        879    +79   
  Partials          0          0          

Powered by Codecov. Last update 6e0a25d...dc9c5fe

@facebook-github-bot
Copy link

@cipiripper updated the pull request.

@ghost
Copy link

ghost commented Aug 11, 2016

@cipiripper updated the pull request.

@flovilmart
Copy link
Contributor

Seems that the tests are failing, can you have a look?

@cipiripper
Copy link
Contributor Author

cipiripper commented Aug 12, 2016 via email

@flovilmart
Copy link
Contributor

thanks 👏

@ghost
Copy link

ghost commented Aug 16, 2016

@cipiripper updated the pull request - view changes

@ghost
Copy link

ghost commented Aug 16, 2016

@cipiripper updated the pull request.

return triggerPromise.then(resolve, resolve);
}
else {
return resolve();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure we should call resolve here? What's the rationale?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm. Checking.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@flovilmart Okay, so resolve() resolves the promise maybeRunTrigger returns, I did it the same as in line 197. So if "after" trigger doesn't return a promise, and caller function expects a promise to be resolved it will hang. So we need to resolve it in all code paths: inside the "after" trigger itself, or here in this line if after trigger did not return a promise. For "before" triggers, promise will be resolved using response objects from inside of the trigger. I checked. If I remove that line, a lot of tests fail, because request flow hangs waiting for this promise to be resolved.

@flovilmart flovilmart merged commit 3164b47 into parse-community:master Aug 17, 2016
caoer added a commit to caoer/parse-server that referenced this pull request Aug 29, 2016
* ParsePlatform/master: (100 commits)
  Only allow basic auth credentials with a known appId (parse-community#2574)
  vk.com provider registered (parse-community#2579)
  chore(package): update parse-server-push-adapter to version 1.1.0 (parse-community#2588)
  vk.com auth data manager implemented (parse-community#2578)
  Fix a typo (parse-community#2563)
  Makes sure routes don't overlap and yield a header set error (parse-community#2559)
  Postgres: $all, $and CLP and more (parse-community#2551)
  Changelog 2.2.18 (parse-community#2558)
  chore(package): update winston-daily-rotate-file to version 1.3.0 (parse-community#2547)
  chore(package): update parse-server-s3-adapter to version 1.0.5 (parse-community#2536)
  Adds bcrypt native binding for better login performance (parse-community#2549)
  chore(package): update mongodb to version 2.2.7 (parse-community#2554)
  Make parse-server cloud code logging closer parse.com legacy (parse-community#2550)
  chore(package): update pg-promise to version 5.3.1 (parse-community#2519)
  Postgres: Operations, Hooks, OAuth login, Files support (parse-community#2528)
  Syncing afterSave/afterDelete trigger calls (Issue parse-community#2489) (parse-community#2499)
  Updated README.md (parse-community#2538)
  Fix capitalization, typo, and grammar mistake (parse-community#2533)
  Update ISSUE_TEMPLATE.md
  fix typo (parse-community#2525)
  ...
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

Successfully merging this pull request may close these issues.

5 participants