choria-io/asyncjobs

feat: add context switch to ajc

Closed this issue ยท 8 comments

I use ajc during my local dev. I run a local server with nats server run --jetstream AJC

If I need to restart the server or reboot, NATS won't allow me to pick this context again with the same command, returning the error:

nats: error: context AJC already exist, choose a new instance name or remove it with 'nats context rm AJC', try --help

I rather need to do ๐Ÿ˜ฒ

nats server run --jetstream BJC
nats context select BJC
ajc info --context BJC

Thus all follow-up commands require extra typing to specify a new context. That's a dev nightmare.

I would rather have a context switch option with --select, like it was implemented in nats-cli. This would allow to seamlessly jump around contexts to drop old context or switch between dev/test/prod envs.

What do you think ? ๐Ÿค”

if you shut the nats server run instance down cleanly it will also remove its contexts that it made which should be smoother. So next time no clashes, but if you dont shut it cleanly you can remove those contexts first.

I dont think adding --select really is the way to go here, the default context for all nats related commands is not the domain for ajc to go mess around with, nats cli is there for that.

What I could do is add to nats server run a flag to overwrite contexts, I think that's the most appropriate?

I don't understand what do you mean by "cleanly" shutting down ๐Ÿ˜ฎ . When I start the jetstream, it blocks. When I press ^+c, it stops, but won't remove the context. Running nats server run --jetstream AJC yields in an error.

I started to lift the solution from the nats-cli project. I also believe it's beneficially to be able to switch the contexts, e.g dev to prod

$ nats ctx ls
No known contexts
$ nats server run --jetstream AJC
....
^C
[793437] [INF] Initiating Shutdown...
[793437] [INF] Initiating JetStream Shutdown...
[793437] [INF] JetStream Shutdown
[793437] [INF] Server Exiting..
$ nats ctx ls
No known contexts

Exiting with ^C shuts it nicely and removes contexts. Are you on windows by any chance?

Heh, that doesn't work that nice for me. Shutting down the server leaves data in ~/.config/nats/context/AJC.json and I have this:

โ”‚ AJC*        โ”‚ Local user access for NATS Development instance    โ”‚
โ”‚ AJC_service โ”‚ Local service access for NATS Development instance โ”‚
โ”‚ AJC_system  โ”‚ System user access for NATS Development instance   โ”‚

I'm on Ubuntu 21.10 with the AJC master custom build

can you copy/paste what happens when you ^C the server?

^+c - and I see the command line. Nothing special happens.

One thing I do differently is I define some external vars for my local dev containers. I have this on my bash:

# NATS
export NATS_URL=192.168.1.93:37139
export NATS_USER=local
export NATS_PASS=bxNBMyHBomfU87rhtRFqSwJU7A5CXNe9

Every time I restart the NATS server it complains on parameter shadowing. But that okay, since I still need to update port and pass to allow containers to access the NATS server

thats really weird, but sounds like probably you're at the point where you'd be better served by running the proper nats server with a config file so you can have static ports/users/etc

Well, I have a nats-server running with auth on my dev cloud. That works fine up to now. Using nats server run locally produces the above issue.

We may close this issue as non reproducible for now.