Skip to content

Commit

Permalink
concurrency
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason committed Apr 4, 2024
1 parent d7ec7e7 commit 339d1e4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
45 changes: 24 additions & 21 deletions daemon.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import os
import traceback
import redis
import json
import requests
from dotenv import load_dotenv
from engine import Matrix
from concurrent.futures import ThreadPoolExecutor

load_dotenv()

Expand All @@ -16,7 +18,7 @@

def notify_discord(msg):
if DISCORD_URL:
requests.post(DISCORD_URL,json={'content':msg})
requests.post(DISCORD_URL, json={'content': msg})

# get this out of here or refactor with engine
def update_from_env(config):
Expand All @@ -35,30 +37,31 @@ def load_config():
return config

def process_simulation(data):
config = load_config()
config['scenario'] = data
config['environment'] = "configs/largev2.tmj"
notify_discord(f"starting simulation: #{config}")
matrix = Matrix(config)
matrix.boot()
matrix.run_singlethread()
notify_discord(f"finished simulation: #{config}")


print(f'Simulation {simulation_id} completed.')
try:
config = load_config()
config['scenario'] = data
config['environment'] = "configs/largev2.tmj"
notify_discord(f"starting simulation: #{config}")
matrix = Matrix(config)
matrix.boot()
matrix.run_singlethread()
notify_discord(f"finished simulation: #{config}")
except Exception as e:
print(f'Error processing simulation: {e}')
traceback.print_exc()

def main():
print('Starting simulation job daemon...')
while True:
# Fetch a job from the Redis queue
_, job = redis_conn.blpop(QUEUE_NAME)
job_data = json.loads(job)
max_concurrent_jobs = 2
with ThreadPoolExecutor(max_workers=max_concurrent_jobs) as executor:
while True:
# Fetch a job from the Redis queue
_, job = redis_conn.blpop(QUEUE_NAME)
job_data = json.loads(job)

# Process the simulation
try:
process_simulation(job_data)
except Exception as e:
print(f'Error processing simulation: {e}')
# Submit the job to the ThreadPoolExecutor
future = executor.submit(process_simulation, job_data)
future.add_done_callback(lambda _: print('Job completed.'))

if __name__ == '__main__':
main()
Expand Down
2 changes: 2 additions & 0 deletions web/.env.production
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
REDIS_URL=redis://localhost:6379
NEXT_PUBLIC_API_URL=/api/v1/replays
NEXT_PUBLIC_ASSET_DOMAIN=https://replicantlife.com/
NEXT_PUBLIC_CONTENT_DIRECTORY= https://replicantlife.com/
4 changes: 2 additions & 2 deletions web/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ const Sidebar: React.FC<SidebarProps> = (
}
if (showThoughts && step instanceof ThoughtStep) {
const thoughtStep = step as ThoughtStep;
addToAudioQueue(fetchAudioData(simId, thoughtStep.stepId, thoughtStep.substepId, thoughtStep.agentId, browserLanguage,talkStep.content));
addToAudioQueue(fetchAudioData(simId, thoughtStep.stepId, thoughtStep.substepId, thoughtStep.agentId, browserLanguage,thoughtStep.content));
return;
}
});
Expand Down Expand Up @@ -243,7 +243,7 @@ const Sidebar: React.FC<SidebarProps> = (
{renderControls()}
{agentPlacement && <div className={styles.agentInfoContainer}>
<div className={styles.agentModule}>
<AgentSprite agentName={agentPlacement.agentName} isTalking={false} isThinking={false} status={agentPlacement.status} />
<AgentSprite agentName={agentPlacement.agentName} isTalking={false} isThinking={false} status={agentPlacement.status} map="" />
<div className={styles.agentName}>{agentPlacement.agentName}</div>
<div className={styles.thoughtSelector}>
<label>
Expand Down

0 comments on commit 339d1e4

Please sign in to comment.