-
Notifications
You must be signed in to change notification settings - Fork 2
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
Implement txs in event, property and allocator #182
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.
In general:
- Maybe you should have constants for repeated strings or have an object containing the various states, e.g.
const STATES = { COMMIT: 'commit', ABORT: 'abort', ...}
- Possibly have a new line before each case statement to increase readability
- Lint the files
- Any comments that I gave in a server file should be applied to all other server files
static async allocationExistsOrFail(id: string): Promise<void> { | ||
const alloc: AllocationDoc | null = await allocations | ||
.findOne({ id: id }, { projection: { _id: 1 } }); | ||
if (alloc === null) { |
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.
What if you used _.isNil
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.
In this case, it is very clear that the value cannot be undefined
(note that the type of alloc
defined in the line above is AllocationDoc | null
)
.findOne( | ||
{id: allocationId, 'assignments.resourceId': resourceId}, | ||
{ projection: { _id: 1 } }); | ||
if (alloc === null) { |
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.
See above
allocationId, resourceId); | ||
const updateObj = await allocations | ||
.updateOne( | ||
{ |
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.
This query is the same as above. Maybe you can have a query object constant to reduce code repetition
throw new Error(CONCURRENT_UPDATE_ERROR); | ||
} | ||
|
||
return true; |
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.
return pendingUpdateObj.matchedCount === 1
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.
it can't be 0 (because if otherwise an error is thrown) and we are doing updateOne
so it can't be > 1
result: (gqlResp.errors) ? 'no' : 'yes', | ||
payload: gqlResp | ||
}; | ||
case 'abort': |
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.
fall through?
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.
/* fall through */
is not necessary when you have an empty case
if (!_.isEmpty(setObject)) { | ||
await events.updateOne({ id: input.id }, { $set: setObject }); | ||
if (_.isEmpty(setObject)) { | ||
return false; |
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.
throw an error?
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 maybe? It's not crazy to return false
here as it is ok for the update to be empty, but I don't have a strong opinion about it.
[field: string]: any; | ||
} | ||
|
||
interface Pending { |
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.
You don't have this in the other server files. Why is it different for this one?
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.
see ObjectDoc
@@ -43,10 +44,14 @@ export class ShowObjectComponent implements OnInit, OnChanges { | |||
if (!this.gs) { | |||
return; | |||
} | |||
this.properties = await properties( | |||
this.showOnly, this.showExclude, this.fetchProperties.bind(this)); | |||
if (!this.properties) { |
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.
Maybe use !_.isEmpty
?
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.
as it is right now you can pass []
for it to fetch nothing but I guess we don't use that. Either way, this is really not a big deal
@maryam-a ready! |
Note that we have: interface Context {
reqType: 'vote' | 'commit' | 'abort' | undefined;
...
} so if you have a typo in e.g., |
"startServer": true, | ||
"actions": { | ||
"package": { | ||
"include": [ "src/app/allocator/**" ] |
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.
./src/app/allocator/**
to support Windows
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.
Are you sure it doesn't work on Windows? We are getting the cwd with process.cwd()
and passing that to globs. It should do the right thing.
Adding the dot doesn't work on unix and I don't think it would work on Windows either. See isaacs/node-glob#309
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.
Actually, you are right. Sometimes you have to include the ./
and sometimes you don't so I got confused here.
}, | ||
"app": { | ||
"names": [ | ||
{ "for": "src/app/app.component.html", "use": "allocator-root" } |
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.
same here
}, | ||
"actions": { | ||
"package": { | ||
"include": [ "src/app/event/**" ] |
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.
./src/app/event/**
}, | ||
"app": { | ||
"names": [ | ||
{ "for": "src/app/app.component.html", "use": "event-root" } |
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.
update as above
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.
and all other dvconfig files
@@ -22,7 +22,8 @@ export class ShowObjectComponent implements OnInit, OnChanges { | |||
@Input() showExclude: string[]; | |||
@Output() loadedObject = new EventEmitter<any>(); | |||
|
|||
properties: string[]; | |||
// Internal input | |||
@Input() properties: string[]; |
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.
internal input?
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.
The idea is that the input is not for users to use. It is for actions inside the cliche to pass the fetched properties to show-object
so as to avoid doing an unnecessary request
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.
Why not use private
then?
@@ -22,7 +22,8 @@ export class ShowObjectComponent implements OnInit, OnChanges { | |||
@Input() showExclude: string[]; | |||
@Output() loadedObject = new EventEmitter<any>(); | |||
|
|||
properties: string[]; | |||
// Internal input | |||
@Input() properties: string[]; |
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.
Why not use private
then?
It also updates the dvconfig.json files of these cliches in preparation for #181