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

Cleanup jobs modules #85

Merged
merged 1 commit into from May 1, 2017

Conversation

FlorianSW
Copy link
Member

The following changes was made to scripts in the jobs directory of this project:

  • Changed big if/else control structure for error management to if + early
    return This makes the code a bit easier to read as the indention level is
    kept as low as possible
  • removed commented code
  • removed unused imports/requires and unused declared variables
  • for a consistent use: changed all " to '
  • merged multiple var definition blocks
  • moved variable declarations to the top of modules/functions
  • Changed usage of type-converting comparsion (equality, ==) to strict comparsion (strict
    equality, ===) where usage of type-converting comparsion doesn't seem to be explicitly
    needed. The same applies for non-equality comparsions (!= -> !==)

In this commit, the every5minstat.js script is rewritten to fulfill the things above and
make the code a lot smaller.

@marziman
Copy link
Contributor

@FlorianSW,
I will review this later..

@marziman
Copy link
Contributor

@FlorianSW I tried to check your PR but I have merge conflicts.
Are you going to clean them up?
Thanks mate!
BR Mehmet

@FlorianSW
Copy link
Member Author

Hi @marziman. It seems, that the branch is mergeable with the openhab/openhab-cloud@master, so probably you made some changes to your copy locally?

@digitaldan
Copy link
Contributor

@FlorianSW the branch works fine for me.

@marziman
Copy link
Contributor

@FlorianSW got it!
I had some changes and I am now back on track.
Testing and checking out the cool stuff :-)

var openhab = openhabs[i];

if (openhab.last_email_notification && openhab.last_email_notification > date3DaysAgo) {
continue;
Copy link
Contributor

Choose a reason for hiding this comment

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

@FlorianSW wow great! The code is much more readable and cleaner now!
Great job! I will deep more into this after merging your other PR.

new Date()
],
function (err, result) {
logger.info('openHAB-cloud: every5min statistics collection job finished');
Copy link
Contributor

Choose a reason for hiding this comment

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

@FlorianSW Same here. Thanks for your effort.
Will test this asap on my instance.


// number of invocations of the finishSent() function to know, when all requests are finished to track multiple
// async actions
expectedFinishCount = 6;
Copy link
Contributor

Choose a reason for hiding this comment

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

So instead of tracking the responses like this, would using promises and Promise.all() be a more standard approach?
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all

Copy link
Contributor

Choose a reason for hiding this comment

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

So i posted this 2 days ago, but did not click the "start review" button, that's twice that new feature from github has bit me.

Copy link
Member Author

Choose a reason for hiding this comment

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

Haha, I thought mongoose can't return a promise (that's why I implemented this tracking with which I'm not very happy myself at all). Now I checked this a bit more and it seems, exec returns a promise, so I'll take a look into this, thanks for the note!

Copy link
Member Author

Choose a reason for hiding this comment

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

That is a way better solution, thanks again for pointing me to it! :)

@FlorianSW FlorianSW force-pushed the general/code-readability-jobs branch from e9aad92 to eb11531 Compare April 26, 2017 21:44
The following changes was made to scripts in the jobs directory of this project:

* Changed big if/else control structure for error management to if + early
  return This makes the code a bit easier to read as the indention level is
  kept as low as possible
* removed commented code
* removed unused imports/requires and unused declared variables
* for a consistent use: changed all " to '
* merged multiple var definition blocks
* moved variable declarations to the top of modules/functions
* Changed usage of type-converting comparsion (equality, ==) to strict comparsion (strict
  equality, ===) where usage of type-converting comparsion doesn't seem to be explicitly
  needed. The same applies for non-equality comparsions (!= -> !==)

In this commit, the every5minstat.js script is rewritten to fulfill the things above and
make the code a lot smaller.
@FlorianSW FlorianSW force-pushed the general/code-readability-jobs branch from eb11531 to 245b096 Compare April 26, 2017 21:46
promises.push(Invitation.count({used:false}, countCallback.bind('invitationUnusedCount')).exec());
promises.push(UserDevice.count({}, countCallback.bind('userDeviceCount')).exec());

Promise.all(promises).then(saveStats);
Copy link
Contributor

Choose a reason for hiding this comment

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

@FlorianSW LGTM, I just need to run it on my test instance tonight or tomorrow.

Copy link
Member Author

Choose a reason for hiding this comment

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

no hurry, thanks for your review! :)

@digitaldan
Copy link
Contributor

Thanks!

@digitaldan digitaldan merged commit 2a513e0 into openhab:master May 1, 2017
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.

None yet

3 participants