💌 A beautiful, fast and fully open source mail client for Mac, Windows and Linux.
Find a file
Evan Morikawa 092c28d2c0 fix(tasks): don't continue if dependent task fails
Summary:
Fixes T4291

If I made a final edit to a pre-existing draft and sent, we'd queue a
`SyncbackDraftTask` before a `SendDraftTask`. This is important because
since we have a valid draft `server_id`, the `SendDraftTask` will send by
server_id, not by POSTing the whole body.

If the `SyncbackDraftTask` fails, then we had a very serious issue whereby
the `SendDraftTask` would keep on sending. Unfortunately the server never
got the latest changes and sent the wrong version of the draft. This
incorrect version would show up later when the `/send` endpoint returned
the message that got actually sent.

The solution was to make any queued `SendDraftTask` fail if a dependent
`SyncbackDraftTask` failed.

This meant we needed to make the requirements for `shouldWaitForTask`
stricter, and block if tasks failed.

Unfortunatley there was no infrastructure in place to do this.

The first change was to change `shouldWaitForTask` to `isDependentTask`.
If we're going to fail when a dependent task fails, I wanted the method
name to reflect this.

Now, if a dependent task fails, we recursively check the dependency tree
(and check for cycles) and `dequeue` anything that needed that to succeed.

I chose `dequeue` as the default action because it seemed as though all
current uses of `shouldWaitForTask` really should bail if their
dependencies fail. It's possible you don't want your task dequeued in this
dependency case. You can return the special `Task.DO_NOT_DEQUEUE_ME`
constant from the `onDependentTaskError` method.

When a task gets dequeued because of the reason above, the
`onDependentTaskError` callback gets fired. This gives tasks like the
`SendDraftTask` a chance to notify the user that it bailed. Not all tasks
need to notify.

The next big issue was a better way to determine if a task truely errored
to the point that we need to dequeue dependencies. In the Developer Status
area we were showing tasks that had errored as "Green" because we caught
the error and resolved with `Task.Status.Finished`. This used to be fine
since nothing life-or-death cared if a task errored or not. Now that it
might cause abortions down the line, we needed a more robust method then
this.

For one I changed `Task.Status.Finished` to a variety of finish types
including `Task.Status.Success`. The way you "error" out is to `throw` or
`Promise.reject` an `Error` object from the `performRemote` method. This
allows us to propagate API errors up, and acts as a safety net that can
catch any malformed code or unexpected responses.

The developer bar now shows a much richer set of statuses instead of a
binary one, which was REALLY helpful in debugging this. We also record
when a Task got dequeued because of the conditions introduced here.

Once all this was working we still had an issue of sending old drafts.

If after a `SyncbackDraftTask` failed, now we'd block the send and notify
the users as such. However, if we tried to send again, there was a
separate issue whereby we wouldn't queue another `SyncbackDraftTask` to
update the server with the latest information. Since our changes were
persisted to the DB, we thought we had no changes, and therefore didn't
need to queue a `SyncbackDraftTask`.

The fix to this is to always force the creation of a `SyncbackDraftTask`
before send regardless of the state of the `DraftStoreProxy`.

Test Plan: new tests. Lots of manual testing

Reviewers: bengotow

Reviewed By: bengotow

Subscribers: mg

Maniphest Tasks: T4291

Differential Revision: https://phab.nylas.com/D2156
2015-10-21 10:33:43 -07:00
apm Update APM to 1.1.1 2015-10-06 23:35:03 -04:00
build ci(mac): Rename the app Nylas N1 on the Mac 2015-10-20 18:36:39 -07:00
docs Fix Broken link to DraftStoreExtensions.md 2015-10-11 17:36:13 -07:00
dot-nylas fix(onboarding): Invitation code system, just in case 2015-10-04 16:49:41 -07:00
examples fix(send-availability): Make the package load into popout composers 2015-10-07 11:45:46 -07:00
internal_packages fix(tasks): don't continue if dependent task fails 2015-10-21 10:33:43 -07:00
keymaps
menus feat(dev-mode): Toggle dev mode, sticky through restarts 2015-10-03 19:04:19 -07:00
script ci(mac): Rename the app Nylas N1 on the Mac 2015-10-20 18:36:39 -07:00
spec fix(tasks): don't continue if dependent task fails 2015-10-21 10:33:43 -07:00
src fix(tasks): don't continue if dependent task fails 2015-10-21 10:33:43 -07:00
static fix(theme): more consistent styles for dark-mode theme 2015-10-09 16:05:26 -07:00
.gitignore ignore gh-pages files 2015-10-02 14:47:33 -07:00
.travis.yml fix(travis): disable node 4 for now 2015-10-07 22:52:20 -04:00
CONTRIBUTING.md fix(contributing): Clarify setup instructions for open source stack 2015-10-13 12:04:23 -07:00
LICENSE.md meta(license): Add GPLv3 License 2015-10-01 10:23:42 -07:00
N1.sh Properly exit out of N1.sh if script/bootstrap hasn't been run yet. 2015-10-04 12:30:37 -07:00
package.json bump(version): 0.3.17 2015-10-20 15:06:36 -07:00
README.md Update CONTRIBUTING.md and README.md to remove node requirement 2015-10-07 17:18:41 -07:00

N1 Logo

N1 Screenshot

N1 is an open-source mail client built on the modern web with Electron, React, and Flux. It is designed to be extensible, so it's easy to create new experiences and workflows around email. N1 is built on the Nylas Sync Engine which is also open source free software.

Build Status Slack Invite Button

Download N1

You can download compiled versions of N1 for Mac OS X and Linux from https://nylas.com/N1. You can also build and run N1 on Windows. A Windows distribution is coming soon!

Build A Plugin

Plugins lie at the heart of N1 and give it it's powerful features. Building your own plugins allows you to integrate the app with other tools, experiment with new workflows, and more. Follow the Getting Started guide to write your first plugin in 5 minutes.

If you would like to run the N1 source and contribute, check out our contributing guide

Running Locally

By default the N1 source points to our hosted version of the Nylas Sync Engine; however, the Sync Engine is open source and you can run it yourself.

Feature Requests / Package Ideas

Have an idea for a package, or a feature you'd love to see in N1? Check out our public Trello board to contribute your thoughts and vote on existing ideas.