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

173 messenger refactor #245

Closed
wants to merge 54 commits into from
Closed

173 messenger refactor #245

wants to merge 54 commits into from

Conversation

sqweelygig
Copy link
Contributor

THIS PR SHOULD NOT BE MERGED

I'm creating this PR to assist in providing structured feedback on the current state of SyncBot.

At the moment it creates new threads between flowdock and forums. To add to this is front, new comments, backporting and rebasing (not necessarily in that order)

@sqweelygig sqweelygig requested a review from hedss August 11, 2017 17:30
@resin-io-modules-versionbot
Copy link
Contributor

@sqweelygig, status checks have failed for this PR. Please make appropriate changes and recommit.

@hedss
Copy link
Contributor

hedss commented Aug 18, 2017

@sqweelygig Sorry, I just have not had time to get round to this this week, been an utterly manic week. I'll be doing this first thing Monday though (obviously won't be a full review, just architecture).

Copy link
Contributor

@hedss hedss left a comment

Choose a reason for hiding this comment

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

Architecture generally looks good to me.

I've commented on a few things of note, but nothing really style related or actual implementation of translators/messenger service, etc.

@@ -0,0 +1,5893 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

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

NPM 5's package-lock.json is currently (unless I've missed something) a bit 'up in the air' (npm/npm#16866). I'd rather not commit the lock file until it's extremely clear as to what the flow is (there doesn't appear to be consistency).

Additionally, we may only want to eventually commit to the application version of ProcBots, and not the library. It needs discussion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That one slipped through, not deliberate, thanks for catching. For now I have put it in the .gitignore.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note to self: done.

@@ -0,0 +1,2 @@
import TypedError = require('typed-error');
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm against this on the principal that it's a very specific error class, and we'd end up with them dotted all over the place. I'm far more in favour of including any error type that's associated with a class as a definition in the class itself (look at https://github.com/resin-io-modules/resin-procbots/blob/master/lib/services/github.ts#L60 as an example).
For that reason, I think there should be a ProcBotError type, that exists in procbot.ts. This would include both code and message, where code is from a const enumerated type defined in procbot-types.ds. This is therefore one such ProcBotError error type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note to self: Done.

const context = data.contexts[this.serviceName] as ServiceEmitContext;
if (!context) {
return Promise.resolve({
err: new ContextAbsentError(`No ${this.serviceName} context`),
Copy link
Contributor

Choose a reason for hiding this comment

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

As previous comment, this could by a specific ProcBotError, eg. new ProcBotError({ code: 123, message: No ${this.serviceName} context)}).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note to self: Done.

* - provide a `apiHandle` getter, which should return the underlying object that executes the requests.
* - enqueue your events with `context` and `event`, as per `UtilityServiceEvent`.
*/
export abstract class ServiceUtilities<T> extends WorkerClient<T> implements ServiceListener, ServiceEmitter {
Copy link
Contributor

Choose a reason for hiding this comment

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

@pimterry pointed out that this isn't really utilities in the strict sense of the word, as Services inherit from it if they want to use it. I don't really like AbstractService as a Service doesn't have to inherit from it. ServiceParent? ServiceFramework? I have no idea! 😺

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note to self: Done, ServiceScaffold.

import { ServiceEvent } from './service-types';

/** Data object the ensures the existence of context and event for serviceUtilities. */
export interface UtilityServiceEvent extends ServiceEvent {
Copy link
Contributor

Choose a reason for hiding this comment

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

The event should probably use the same nomenclature as the class that uses it, ServiceUtilityEvent, maybe.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note to self: Done

}
public request(requestOptions: UrlOptions & RequestPromiseOptions): Promise<DiscourseResponse> {
// This type massages request-promise into bluebird
return new Promise((resolve) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

If we're using request-promise, why is there a new Promise here instead of just returning the result of request?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note to self: Done

public constructor(data: FlowdockConstructor, listen = true ) {
super(listen);
this.data = data;
constructor(data: FlowdockConnectionDetails, listen: boolean) {
Copy link
Contributor

Choose a reason for hiding this comment

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

As per Front comments, listen could be an option in FlowdockConnectionDetails.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To discuss.

this.session = new Session(data.token);
this.org = data.organization;
if (listen) {
this.startListening();
Copy link
Contributor

Choose a reason for hiding this comment

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

Drop startListening() method and add the code into this block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note to self: Done

export function createMessageService(data: FrontConstructor): Messenger {
return new FrontService(data, false);
}
// /*
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The Front service has currently been put temporarily out of scope, as indicated by the massive commenting, and will be coming back into the fold in a couple of days.

this.translators[serviceName] = Translator.createTranslator(serviceName, subConnectionDetails, data.dataHubs);
});
if (listen) {
this.startListening(data.subServices);
Copy link
Contributor

Choose a reason for hiding this comment

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

Move the startListening() method into this body.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note to self: Done

@resin-io-modules-versionbot
Copy link
Contributor

@sqweelygig, status checks have failed for this PR. Please make appropriate changes and recommit.

@resin-io-modules-versionbot
Copy link
Contributor

@sqweelygig, status checks have failed for this PR. Please make appropriate changes and recommit.

@resin-io-modules-versionbot
Copy link
Contributor

@sqweelygig, status checks have failed for this PR. Please make appropriate changes and recommit.

@sqweelygig sqweelygig closed this Aug 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
ProcBot Work
In Progress
Development

Successfully merging this pull request may close these issues.

None yet

2 participants