Skip to content

Commit

Permalink
Add get-batch-data endpoint to master.
Browse files Browse the repository at this point in the history
  • Loading branch information
FiveMovesAhead committed Jan 18, 2025
1 parent 101ca13 commit ec5e09d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
39 changes: 39 additions & 0 deletions tig-benchmarker/master/master/client_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,45 @@ async def get_jobs():
headers = {"Accept-Encoding": "gzip"}
)

@self.app.get("/get-batch-data/{batch_id}")
async def get_batch_data(batch_id: str):
benchmark_id, batch_idx = batch_id.split("_")
result = get_db_conn().fetch_one(
f"""
SELECT
JSONB_BUILD_OBJECT(
'id', A.benchmark_id || '_' || A.batch_idx,
'benchmark_id', A.benchmark_id,
'start_nonce', A.batch_idx * B.batch_size,
'num_nonces', LEAST(B.batch_size, B.num_nonces - A.batch_idx * B.batch_size),
'settings', B.settings,
'sampled_nonces', NULL,
'runtime_config', B.runtime_config,
'download_url', B.download_url,
'rand_hash', B.rand_hash,
'batch_size', B.batch_size,
'batch_idx', A.batch_idx
) AS batch,
C.merkle_root,
C.solution_nonces,
C.merkle_proofs
FROM root_batch A
INNER JOIN job B
ON A.benchmark_id = '{benchmark_id}'
AND A.batch_idx = {batch_idx}
AND A.benchmark_id = B.benchmark_id
INNER JOIN batch_data C
ON A.benchmark_id = C.benchmark_id
AND A.batch_idx = C.batch_idx
"""
)

return JSONResponse(
content=dict(result),
status_code=200,
headers = {"Accept-Encoding": "gzip"}
)

def start(self):
def run():
self.app = FastAPI()
Expand Down
2 changes: 1 addition & 1 deletion tig-benchmarker/nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ http {
server_name localhost;

# Master Service - specific endpoints
location ~ ^/(get-config|stop|update-config|get-jobs|get-latest-data) {
location ~ ^/(get-config|stop|update-config|get-batch-data|get-jobs|get-latest-data) {
proxy_pass http://master:3336;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
Expand Down

0 comments on commit ec5e09d

Please sign in to comment.