medic / cht-user-management

GNU Affero General Public License v3.0
3 stars 1 forks source link

feat(#12): cloud-based execution of move contact #177

Closed paulpascal closed 3 months ago

paulpascal commented 4 months ago

Closes: #12

This PR introduces a cloud-based execution of the move-contact feature, enhancing user experience by replacing the previous cht-conf command-line approach.

To achieve this, we've implemented bullmq, a powerful and flexible queue system built on Redis.

Here's a breakdown of the process:

  1. Upon initiating a contact move, essential details such as contact_id, parent_id, instanceUrl, and the current sessionToken (encrypted) are compiled and submitted as a job to the MOVE_CONTACT_QUEUE.

  2. A dedicated worker monitors this queue, processing incoming jobs:

    • It has the flexibility to defer processing based on predefined logic, allowing for scheduled execution.
    • Alternatively, it can proceed to execute the cht-conf command via a child_process, utilizing all pertinent job data, including the decrypted sessionToken.
  3. Upon successful execution, the job is marked as completed. In case of any failures, the job is flagged accordingly. Users can conveniently track job statuses directly from the user management tool's dashboard.

[!NOTE] Enabling cht-conf to support session tokens required implementing some modifications, detailed here. (_the session token is initial got from _session request_)

paulpascal commented 4 months ago

Thanks @mrjones-plip for this great review, I will be going through them one by one and get back to you. About the publishing, I was also thinking, should it be possible to do it the same way we did for the current version (using publish script). Maybe it will need some updates on the current docker stuff I did? (Forgive if I'm sinning here 🥲 I am not a 😅pro on docker)

cc: @kennsippell

paulpascal commented 4 months ago

Thanks @kennsippell , great review. Really appreciate. Will be making the right adjustment

kennsippell commented 4 months ago

Testing today:

  1. If redis service is not running, the worker process logs errors but doesn't exit. Seems it should fail fast.
  2. The Cht command output: output with all the new lines is extremely verbose. I think we can just output the raw data. It'd also be nice to output the actual command being executed.'
  3. Can we add json_docs and upload-docs.*.json into .gitignore since this is created when worker thread is run in active directory.
  4. We need to think about how to handle the case where the docker container is killed (eg. deployment) while a job is executing. This can leave contacts in a broken state.
  5. adding new job to MOVE_CONTACT_QUEUE with [object Object]
paulpascal commented 3 months ago

Hi, @mrjones-plip it took a bit but finally got all the docker feedback addressed 🥲. Would you like to check it back when ever you have time?

@kennsippell, i have fixed the delay stuff as well.

Thanks

paulpascal commented 3 months ago

Thanks @mrjones-plip and @kennsippell for your great reviews 🔥.

Really appreciate that, will go through it thoroughly.

paulpascal commented 3 months ago
docker logs cht-user-management-cht-user-management-1

Error: connect ECONNREFUSED 192.168.16.2:6378
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1606:16) {
  errno: -111,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '192.168.16.2',
  port: 6378
}

does this work for you?

Yes @mrjones-plip, it works for me, we can please have a little sync on that if its okay with you.

paulpascal commented 3 months ago

... I still was unable to log in, so please be sure and test this with a clean set up to ensure there's no regressions!

Thanks @mrjones-plip , I will make sure to have that working.