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

Log events #110

Merged
merged 10 commits into from
Oct 18, 2020
Merged

Log events #110

merged 10 commits into from
Oct 18, 2020

Conversation

baruchiro
Copy link
Collaborator

image

Using the EventEmitter, I'm printing the events to the UI, to see the process and errors if any.

It's very hard to work with the current EventEmitter design. You have to declare manually all the EventNames, and you don't have type-checking for that.
You can achieve type-checking, of course, but it creates a very complicated code.
I think we need to define the events as classes instead of interfaces, and yes, it will be noises in the backend, so maybe create a helper method to create these objects.

Anyway, don't know. We need more helper methods here.

@baruchiro baruchiro added this to In progress in Publish an MVP Oct 4, 2020
@baruchiro baruchiro moved this from In progress to Under Review in Publish an MVP Oct 6, 2020
# Conflicts:
#	package.json
#	src/main.ts
#	yarn.lock
data() {
setup() {
const inProgress = ref(false);
const succeeded = ref('unknown' as keyof typeof colors);
Copy link
Owner

Choose a reason for hiding this comment

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

This doesn't ever change. Don't think this was what you intended.
Need to add back the logic that updates according to result of scraping

Copy link
Owner

Choose a reason for hiding this comment

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

In general I think we should replace succeeded and in progress with a single status. Something like:
status: NOT_STARTED | IN_PROGRESS | SUCCESS | FAILURE

Then colors becomes STATUS_COLORS: Record<ScrapingStatus, string | null>

Copy link
Owner

Choose a reason for hiding this comment

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

You can actually use the event emitter for setting the status instead of awaiting the promise (not a must):

eventPublisher.on(EventNames.IMPORT_PROCESS_START, () => {
// IN_PROGRESS
});

eventPublisher.on(EventNames.IMPORT_PROCESS_END, () => {
// SUCCESS
});

eventPublisher.on(EventNames.GENERAL_ERROR, () => {
// ERROR
});

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In general I think we should replace succeeded and in progress with a single status. Something like:
status: NOT_STARTED | IN_PROGRESS | SUCCESS | FAILURE

Then colors becomes STATUS_COLORS: Record<ScrapingStatus, string | null>

I think I don't understand... You just suggesting to change the unknown | success | fail with these NOT_STARTED | IN_PROGRESS | SUCCESS | FAILURE?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You can actually use the event emitter for setting the status instead of awaiting the promise (not a must):

eventPublisher.on(EventNames.IMPORT_PROCESS_START, () => {
// IN_PROGRESS
});

eventPublisher.on(EventNames.IMPORT_PROCESS_END, () => {
// SUCCESS
});

eventPublisher.on(EventNames.GENERAL_ERROR, () => {
// ERROR
});

As I said before, I don't like to use EventEmitter as a "serial" flow, because I think it is less readable.

Copy link
Owner

Choose a reason for hiding this comment

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

Discussed on the phone. Easier to communicate that way 🙂

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I did it. I started with enum but I think for now we can just use the keyof typeof statusToColor

src/components/app/LogsEventEmitter.ts Show resolved Hide resolved
@brafdlog
Copy link
Owner

brafdlog commented Oct 11, 2020

image

Using the EventEmitter, I'm printing the events to the UI, to see the process and errors if any.

It's very hard to work with the current EventEmitter design. You have to declare manually all the EventNames, and you don't have type-checking for that.
You can achieve type-checking, of course, but it creates a very complicated code.
I think we need to define the events as classes instead of interfaces, and yes, it will be noises in the backend, so maybe create a helper method to create these objects.

Anyway, don't know. We need more helper methods here.

I don't fully understand what you mean. You could either listen with onAny if the use case is very generic (as it is in the current implementation of the logger). In this case (as an any generic code) you can only assume that the type is BudgetTrackingEvent which doesn't give you much, but you are listening on everything. Alternatively if your use case is more specific (which I think will happen in the next iterations of implementing the progress indication) you can listen for specific events and get them fully typed.

I am not saying this implementation is optimal, I am just not sure what are the actual pain points so we can improve the current design. We can discuss this on the phone if you want.

@baruchiro
Copy link
Collaborator Author

I can't tell you exactly what is the pain. Of course, I can listen to a specific event to get the specific type. But I want it to be generic.

Also, take the message as an example- I expect all the events to have a message generated by the other event fields, I think if we will use classes, we can create the message as a function.

In short, I think the better is to let you try to improve my code, if you want and if you have time, and see if it hurts you.

@brafdlog
Copy link
Owner

I can't tell you exactly what is the pain. Of course, I can listen to a specific event to get the specific type. But I want it to be generic.

Also, take the message as an example- I expect all the events to have a message generated by the other event fields, I think if we will use classes, we can create the message as a function.

In short, I think the better is to let you try to improve my code, if you want and if you have time, and see if it hurts you.

Thats fine. As I said we will have a real use case once we implement the progress indication. For now I suggest just the changes in the comments

@baruchiro
Copy link
Collaborator Author

@brafdlog Ready, waiting for your approval.

@baruchiro baruchiro merged commit 9e8fe43 into unifyRepos Oct 18, 2020
Publish an MVP automation moved this from Under Review to Done Oct 18, 2020
@baruchiro baruchiro deleted the logEvents branch October 18, 2020 18:24
brafdlog pushed a commit that referenced this pull request Dec 22, 2020
Move DataTable from ElementUI to Vuetify
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

2 participants