aboutsummaryrefslogtreecommitdiff
path: root/gn3/api/async_commands.py
blob: f8400c8ef402403d4900cd5eb4ebea11e9b55df7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
"""Endpoints and functions concerning commands run in external processes."""
import json

import redis
from flask import jsonify, Blueprint

async_commands = Blueprint("async_commands", __name__)

@async_commands.route("/state/<command_id>")
def command_state(command_id):
    with redis.Redis() as rconn:
        state = rconn.hgetall(name=command_id)
        if not state:
            return jsonify(
                status=404,
                error="The command id provided does not exist.")
        state = {
            key.decode("utf-8"): val.decode("utf8")
            for key,val in state.items()
        }
        return jsonify(state)