fixes
This commit is contained in:
@@ -62,38 +62,44 @@ def receive_state():
|
||||
# ------------------------------------------------------------------
|
||||
# GET /api/commands/pending
|
||||
# Tampermonkey polls this to get the next command to execute.
|
||||
# Returns ONE command at a time, marks it as 'executing'.
|
||||
# Returns one 'build' AND one 'recruit' command independently,
|
||||
# so both queues are served in parallel without blocking each other.
|
||||
# ------------------------------------------------------------------
|
||||
@api.route('/api/commands/pending', methods=['GET'])
|
||||
def get_pending_command():
|
||||
conn = get_db()
|
||||
c = conn.cursor()
|
||||
def _fetch_pending_of_type(c, cmd_type):
|
||||
row = c.execute('''
|
||||
SELECT * FROM commands
|
||||
WHERE status = 'pending'
|
||||
WHERE status = 'pending' AND type = ?
|
||||
ORDER BY id ASC
|
||||
LIMIT 1
|
||||
''').fetchone()
|
||||
|
||||
''', (cmd_type,)).fetchone()
|
||||
if not row:
|
||||
conn.close()
|
||||
return jsonify({'command': None})
|
||||
|
||||
return None
|
||||
c.execute('''
|
||||
UPDATE commands
|
||||
SET status = 'executing', updated_at = ?
|
||||
WHERE id = ?
|
||||
''', (datetime.utcnow().isoformat(), row['id']))
|
||||
return {
|
||||
'id': row['id'],
|
||||
'town_id': row['town_id'],
|
||||
'type': row['type'],
|
||||
'payload': json.loads(row['payload'])
|
||||
}
|
||||
|
||||
@api.route('/api/commands/pending', methods=['GET'])
|
||||
def get_pending_command():
|
||||
conn = get_db()
|
||||
c = conn.cursor()
|
||||
|
||||
build_cmd = _fetch_pending_of_type(c, 'build')
|
||||
recruit_cmd = _fetch_pending_of_type(c, 'recruit')
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
return jsonify({
|
||||
'command': {
|
||||
'id': row['id'],
|
||||
'town_id': row['town_id'],
|
||||
'type': row['type'],
|
||||
'payload': json.loads(row['payload'])
|
||||
}
|
||||
'build': build_cmd,
|
||||
'recruit': recruit_cmd
|
||||
})
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user