Skip to content

Commit

Permalink
Docker compose and expected final release
Browse files Browse the repository at this point in the history
  • Loading branch information
Ctri-The-Third committed Feb 24, 2024
1 parent 5e4cf29 commit 059d39c
Show file tree
Hide file tree
Showing 8 changed files with 314 additions and 137 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,5 @@ behaviours/Z_repro_pathfinder_issue
game_plan.json
custom_game_plan.json
custom_game_plan.json
scripts/PRD-build_push_and_run_dispatcher_container.bat
scripts/PRD-build-push-and-run-compose.bat
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,30 @@ The project also contains a `dispatcher` which based on values in a configured d
dispatcher reads the database for behaviours and 1-off tasks and executes matching `behaviours`
* `conductorWK25.py` - assigns behaviours to ships based on the contents of a custom game plan file like or populates its own default game plan.
* `behaviours\` is a folder of python classes that inherit `generic_behaviour.py`. They all execute and initialise in the same way, and can be run from command line, or automatically the dispatcher.



## Setup

You need to set the following environment variables:

If you wanted to use a .env file, you could use the following format:

```bash
ST_TOKEN=eyJh....
ST_DB_HOST=spacetraders_db_instance
ST_DB_PASSWORD=spacetraders_pass
ST_DB_NAME=spacetraders
ST_DB_PORT=5432
POSTGRES_PASSWORD=spacetraders_pass
```

## Deploy

You can use docker-compose to deploy the application.

```bash
docker compose -f "scripts\all_in_one_compose.yml" up -d
```

This will host the UI on port 3000, the DB on port 5432, and execute the dispatcher application with whatever token is specified in the .env file.
13 changes: 3 additions & 10 deletions behaviours/generic_behaviour.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ def __init__(
self.logger.warning(
"you're passing the connection in again, shouldn't be doing that. "
)
saved_data = json.load(open(config_file_name, "r+"))
token = None
try:
self.priority = int(self.behaviour_params.get("priority", 5))
except ValueError:
Expand All @@ -51,13 +49,7 @@ def __init__(
"priority value is invalid, defaulting to 5. Value was %s",
self.behaviour_params.get("priority", 5),
)
for agent in saved_data["agents"]:
if agent.get("username", "") == agent_name:
token = agent["token"]
break
if not token:
# register the user
pass
token = os.environ.get("ST_TOKEN", None)
db_host = os.environ.get("ST_DB_HOST", None)
db_port = os.environ.get("ST_DB_PORT", None)
db_name = os.environ.get("ST_DB_NAME", None)
Expand Down Expand Up @@ -906,6 +898,7 @@ def go_and_buy(
if not resp:
self.st.view_my_self(True)
self.st.ships_view_one(ship.name, True)
self.log_market_changes(ship.nav.waypoint_symbol)
resp = self.purchase_what_you_can(
target_tradegood, min(max_to_buy, ship.cargo_space_remaining)
)
Expand Down Expand Up @@ -1084,7 +1077,7 @@ def sleep_until_arrived(self):
self = bhvr
st = self.st
ship = self.ship

bhvr.sell_all_cargo()
current_system = st.systems_view_one(ship.nav.system_symbol)
factions = st.list_factions()
for faction in factions:
Expand Down
1 change: 0 additions & 1 deletion behaviours/trade_best_intrasolar.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ def get_best_trade(self):
ship = f"{agent}-{ship_number}"
behaviour_params = {
"priority": 3,
"target_sys": "X1-DM68",
}

bhvr = TradeBestInSystem(agent, ship, behaviour_params or {})
Expand Down
60 changes: 60 additions & 0 deletions blog/Version 2.1.5 (week 31&32).md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ With Justin back and active (and already in first place), the focus is going to
Node-V isn't doing anything at all, when I restarted the dispatcher I got a bunch of errors from it attempting to map to a system it's not in?
Turns out we need to purge the cache between resets. Maybe the clint should do that if the system's dates don't match up with the service?


## performance

| stat | Node U (exp) | node V (26-27) | node C (27-28) |
Expand All @@ -22,3 +23,62 @@ Turns out we need to purge the cache between resets. Maybe the clint should do t
| average delay |
| CPH |
| CPR |


## Stagnation

It's really feeling like we've not made any progress for a while.
With that in mind, it might be good to draw a line under this client, fix some of the structural issues with the SDK, tag it v2.0 and start again.



### So what worked?

* The "trade best" doesn't compete with Justin but it's very good in principle.
* The "Chain Trade" technology worked very well.
* Having generic behaviour methods for travel, refuel, buy, sell, extract_till_full
* The "contracts" and both "management" behviours worked well but sometimes had downtime.
* straightforward "mine and go sell" works
* The request throttler and ship-specific priorities
* The pathfinder did great except for assumption that it always had the latest data.
* Putting the DB and and the UI in containers was great for resets.
* The UI being publicly hosted was great

### What didn't work?

* Weekly reset and caching issues were a pain. If we want an "always in memory" approach, the SDK will need to be more robust about managing when market data is old.
* The UI being a seperate process meant exposing logs to the player and getting feedback from actions was a right pain.
* The UI being an "all in one window" ended up being harder to work with than I'd hoped.
* Mistakes made in the SDK were hard to fix (seperate tables for markets etc...)
* A limitation of the old design was that it really was one-ship per client, controlled by the DB, with the potential of split behaviour.


### What should our new client do?

* We should try to be as stateless as possible to allow for quick "off then on" again.
* Haulers should have three priorities - strengthen markets, trade ABUNDANT/ HIGH, and then haul mining goods & fuel.
* Have a unified system for picking what to do next, and a thread-safe mechanism for avoiding collisions - ships should be aware of each others actions, states, and behaviour.
* Have a UI that works on mobile.
* Have a UI that lets you take direct control of a ship, and activate any of our "blocks" of code (Travel, refuel, extract, buy, sell, build etc...)
* Have a UI that shows market changes over time.
* Have a UI that renders a production chain.
* Allow multi-token operation - our public UI should be for any player to control their ship.
* work when the user isn't on the browser
* Visualise ship movements / distance in real time.
* Have a comparison mode for previous resets.
#### Archive the current client

* Get the dispatcher container up to speed, it should have a sigterm intercept for graceful shutdowns.
* the sigterm signal is being captured
* the compose file is written
* [the DB container is out of date]
* The UI container is able to connect to the DB
* the dispatcher is able to connect to the DB
* Have a cron job that spins up a new container every 3 hours


#### Development milestone 1

* Token management from the UI.
* Logs fedback to the user (websocket?)
* execute move, buy, sell blocks to ships from the UI.
8 changes: 6 additions & 2 deletions dispatcher.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ copy ./requirements.txt ./requirements.txt
run python -m pip install -r requirements.txt

workdir spacetraders_sdk


run chmod +x ./setup.sh
run /spacetraders_sdk/setup.sh
run python3 -m build
run python3 -m pip install dist/straders-2.1.4-py3-none-any.whl --force-reinstall

workdir ..

Expand All @@ -15,4 +18,5 @@ copy . .
ENV ST_DB_USER=spacetraders


CMD python dispatcherWK16.py
CMD python dispatcherWK25.py

Loading

0 comments on commit 059d39c

Please sign in to comment.