DevelopingSpace / starchart

A self-serve tool for managing custom domains and certificates
MIT License
20 stars 13 forks source link

DNS flow refactors #333

Closed ghost closed 1 year ago

ghost commented 1 year ago

I'd like to start a discussion about this file's TS declarations, because I'm quite certain it's wrong: https://github.com/DevelopingSpace/starchart/blob/main/app/queues/dns/dns-flow.server.ts First, we are trying to use JobRecord for absolutely everything. Basically all the workers and exported flow initiator functions all use this, and we are trying to twist it to suite the specific use-case. This causes some very hard to follow code, and inappropriate use. I.e., Line 17, name refers to a subdomain only (which was a breaking change, but let's not get bogged down) In Line 18, using name (subdomain) we create fullRecordName which is an FQDN In line 24, we pass this FQDN down as name, so in line 17 name was a subdomain, in line 24 name is FQDN and they are both using the same TS interface. This is wrong.

In my humble opinion:

Genne23v commented 1 year ago

Each worker should be it's own file and should export an interface, of what it exactly expects as input params (data)

@dadolhay I can split dns-flow.server.ts into several files. But the current workers has a benefit by having it all in one file as it's designed to reduce similar code. This is one example.

      switch (workType) {
        case 'create':
          return createRecord(username, type, name.toLowerCase(), value);

        case 'update':
          return upsertRecord(username, type, name.toLowerCase(), value);

        case 'delete':
          return deleteRecord(username, type, name.toLowerCase(), value);

        default:
          throw new UnrecoverableError(`Invalid work type: ${workType}`);
      }

I can define multiple interfaces here. Should we still have this code in separate files?

humphd commented 1 year ago

@Genne23v if it's not convenient to break the file up, don't bother. I just suggested it because our other code does it (for consistency). But it's not critical. Do what's best for the code.

Genne23v commented 1 year ago

@Genne23v if it's not convenient to break the file up, don't bother. I just suggested it because our other code does it (for consistency). But it's not critical. Do what's best for the code.

Thanks for the feedback. I just wanted to make sure that I'm not missing something valuable. I will come up with what I think is the best.

ghost commented 1 year ago

@Genne23v I meant to break up ./dns-record-worker.server. As far as I can see, the switch (workType) part is already repeated in the relevant workers, and I can't see too much reuse between them. IMO, this would help later in correctly structuring the code also. But as always, the decision is yours, I don't want to force my own coding style on anyone.

ghost commented 1 year ago

Just to share my thinking; I usually try to break out stuff that are loosely connected if the file size is > 100 lines. Not always possible but I found that to be a good practice anyways.

Genne23v commented 1 year ago

Thank you for the advice. I don't see much benefit to break the workers at the moment probably because I'm not able to foresee what should be coming next. Before wring more code, I will think more about how it should be handled for better maintainability as well as minimizing the code.