-
Notifications
You must be signed in to change notification settings - Fork 3
chore: Convert the worker.js file into multiple smaller files #38
Conversation
|
On first glance this seems fine, but was there a pressing need to break up a file that was under 500 LOC? |
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.
I split this off because it was causing conflicts in other tests
.eslintrc
Outdated
| // "comma-dangle": ["error", "never"], | ||
| // "quotes": ["error", "double"], |
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.
Wanted to touch base on this one, I think these two rules make sense, if not I can remove them.
The rest of the changes here are just whitespace
lib/worker/messaging.js
Outdated
| if ( | ||
| (start === '[' && end === ']') || | ||
| (start === '{' && end === '}') || | ||
| (start === '"' && end === '"') | ||
| ) { | ||
| return 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.
This is a super simple 'is this string json already' check, if its not, we stringify it anyway! I was not sure of a better way to do this 🤔
lib/worker/messaging.js
Outdated
| function runWith (data, handler) { | ||
| store.run( | ||
| { | ||
| key: data?.key, | ||
| type: data?.type, | ||
| filePath: data?.filePath, | ||
| projectPath: data?.projectPath, | ||
| }, | ||
| handler, | ||
| ); | ||
| } |
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 allows any messages or errors thrown to have the requests context in the response.
This is useful when its an uncaught exception.
lib/worker/worker.js
Outdated
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.
I am not sure I like how this file looks or works... I am considering moving the jobs to their own folder, like:
worker/worker.js
worker/jobs/:job.js
worker/utilites/:utility.js
I think that would make things even clearer
lib/worker/worker.js
Outdated
| Messaging.runWith(data, async () => { | ||
| try { | ||
| if (!data.key) { | ||
| throw new JobKeyError(); | ||
| } | ||
|
|
||
| Messaging.emit(await processMessage(data)); | ||
| } catch (error) { | ||
| Messaging.emitError(handleError(error, data)); | ||
| } | ||
| }); |
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 is now effectivly the only place to respond to requests. It allows for more consise response handling.
All jobs now just return what the job wants to output, or throws an error.
lib/worker/worker.js
Outdated
| try { | ||
| Messaging.emitError(error); | ||
| } finally { | ||
| process.exit(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.
I am not sure we need this anymore, but I wanted to leave this in as I don't want to find out the hard way with a ticket later 😂
|
@savetheclocktower I am gearing up torwards the |
|
Wow, that was not on my radar. Much appreciated. I don't know if you're any good with CI stuff, but our jobs need retrofitting to work with Pulsar. @UziTech pointed me to setup-pulsar a while back, but I haven't had time to investigate, because I'm spending a lot of time working on Pulsar's core. I haven't even gotten far enough to ascertain whether it's mature enough for us to be able to do a simple swap for If you're willing to give this a try, it would be a huge help; otherwise we're in a position where we have to make disruptive changes to the codebase without being able to rely on CI. If it's something you despise doing, then I can give it my best shot. |
|
I can certainly give it a shot 😄 |
|
Strangely, all tests pass when I run The test you skipped works fine for me locally if I un-skip it. If increasing the timeout helps the test pass for you locally, let's try that. |
|
Draft CI found in #39 |
|
mmm, rebase tests failed, will look later 😂 |
lib/job-manager.js
Outdated
| if (worker == null) { | ||
| worker = this.worker; | ||
| } |
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.
Not 100% sure why this worked, I think it's babel doing its thing 🤔
https://node.green/#ES2021-features-Logical-Assignment-----basic-support
lib/node-path-tester.js
Outdated
| let stdout = execSync( | ||
| `${bin} --version`, | ||
| { | ||
| stdio: [ | ||
| 'ignore', // Ignore stdin | ||
| undefined, // return stdout | ||
| 'ignore' // Ignore stderr | ||
| ] | ||
| } | ||
| ); |
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 fixes the random logging of /bin/sh asdasdas not found
|
I'm on macOS, so I'll be of no help, sadly. |
|
I now have all major OS distros installed, my daily driver is also mac 😂 |

This does the following:
worker.jstoworker/worker.jsconvert-results.jsESLint.LintResult[]into atom-linter resultserrors.jseslint.jsfs-utils.jsmessaging.jsworker.js