-
Notifications
You must be signed in to change notification settings - Fork 465
Organize async task queues by network #375
Organize async task queues by network #375
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super pumped about this!
private _start() { | ||
this._queueIntervalIdIfExists = intervalUtils.setAsyncExcludingInterval( | ||
async () => { | ||
const task = this._queue.shift(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename task
to taskAsync
await task(); | ||
}, | ||
this._queueIntervalMs, | ||
_.noop, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should actually handle the error here. If we encounter one, let's log the error to Rollbar and stop the thrown error from crashing the process.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see this is done in the individual actions. It would be cleaner to move it up here, then it only lives in one place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm its a bit tricky because the error reporting is asynchronous, let's sync up if theres a way to fix this
private _dispenseAsset(req: express.Request, res: express.Response, requestedAssetType: RequestedAssetType) { | ||
const networkId = req.params.networkId; | ||
const recipient = req.params.recipient; | ||
const networkConfig = _.get(this._networkConfigByNetworkId, networkId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's simply index in here rather then use _.get
.
* development: (24 commits) Fix Remco's github name in CODEOWNERS Fix ABI error message Stop using definite assignment assertion cause prettier doesn't handle that Special-case ZRXToken snake case conversion Fix linter errors Generate contract wrappers on pre-build Add missing async Remove noImplicitThis Tslint disable no-consecutive-blank-lines in generated files Change compiled sources in contracts Change utils Change tests Add base_contract.ts Remove generated files .gitignore gemerated files Change the list of generated wrappers Change contract templates Add indices for index parameters so that their names don't collide Use abi-gen for events in 0x.js Fix artifacts path ...
dispenserTask = dispenseAssetTasks.dispenseEtherTask(recipient, networkConfig.web3); | ||
break; | ||
case RequestedAssetType.WETH: | ||
dispenserTask = dispenseAssetTasks.dispenseTokenTask(recipient, requestedAssetType, networkConfig.zeroEx); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can these be defaulted to the same case statement body?
case RequestedAssetType.WETH:
case RequestedAssetType.ZRX:
dispenserTask = dispenseAssetTasks.dispenseTokenTask(recipient, requestedAssetType, networkConfig.zeroEx);
break;
Description
Generalized the
RequestQueue
into aDispatchQueue
that serializes any arbitrary asynchronous tasks.Motivation and Context
Because the same address was being used to dispense both ETH and ZRX, sometimes the transaction nonces would get messed up. This fixes that problem by serializing transactions on a per network basis and only advancing the queue once the in-flight transaction resolves.
How Has This Been Tested?
Local testing
Types of changes
Checklist: