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

Implement txs in event, property and allocator #182

Merged
merged 13 commits into from
May 18, 2018
Merged

Conversation

spderosso
Copy link
Member

It also updates the dvconfig.json files of these cliches in preparation for #181

@spderosso spderosso requested a review from maryam-a May 11, 2018 05:29
Copy link
Collaborator

@maryam-a maryam-a left a 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) {
Copy link
Collaborator

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

Copy link
Member Author

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) {
Copy link
Collaborator

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(
{
Copy link
Collaborator

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;
Copy link
Collaborator

Choose a reason for hiding this comment

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

return pendingUpdateObj.matchedCount === 1

Copy link
Member Author

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':
Copy link
Collaborator

Choose a reason for hiding this comment

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

fall through?

Copy link
Member Author

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;
Copy link
Collaborator

Choose a reason for hiding this comment

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

throw an error?

Copy link
Member Author

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 {
Copy link
Collaborator

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?

Copy link
Member Author

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) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe use !_.isEmpty?

Copy link
Member Author

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

@spderosso
Copy link
Member Author

@maryam-a ready!

@spderosso
Copy link
Member Author

Maybe you should have constants for repeated strings or have an object containing the various states, e.g. const STATES = { COMMIT: 'commit', ABORT: 'abort', ...}

Note that we have:

interface Context {                                                                                  
    reqType: 'vote' | 'commit' | 'abort' | undefined; 
    ...
}

so if you have a typo in e.g., commit the compiler will detect it. So the main reason to use an enum is gone because of that. The only thing you gain by having an enum is if in the future we change 'commit' to be some other string but I don't think that's ever going to happen.

"startServer": true,
"actions": {
"package": {
"include": [ "src/app/allocator/**" ]
Copy link
Collaborator

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

Copy link
Member Author

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

Copy link
Collaborator

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" }
Copy link
Collaborator

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/**" ]
Copy link
Collaborator

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" }
Copy link
Collaborator

Choose a reason for hiding this comment

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

update as above

Copy link
Collaborator

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[];
Copy link
Collaborator

Choose a reason for hiding this comment

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

internal input?

Copy link
Member Author

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

Copy link
Collaborator

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[];
Copy link
Collaborator

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?

@spderosso spderosso merged commit 33a3d3e into ops-tmp May 18, 2018
@spderosso spderosso deleted the implement-txs branch September 7, 2018 20:02
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.

2 participants