def task_result(task_id): result = celery.AsyncResult(task_id) if result: if type(result.info) is Exception: return buildError("Task failed due to exception:{}".format(str(result.info.args))) else: return buildSuccess("task submitted", {"state": result.state, "task_id": result.task_id, "result": str(result.info)}) return buildError("Some issue happened")
def summary(): mayRebuildData() summary = dhighlights.get_summary() if summary: return buildSuccess("calculated", summary) else: tasks.taskComputeSummary.delay() return buildError("Summary is not yet available")
def clearcache(): " This will delete cache for all the data " # cache.delete_memoized(status) >>> NOT WORKS # cache.delete_many("flask_cache_view//status") >> NOT WORKS if (request.args.get('key')): dredis.clear(get_param_or_throw(request, "key")) else: dredis.clearAll() return buildSuccess("Clear cache", {"random": random.randint(10, 100)})
def indicator(): "status of the app" candle_type: str = get_param_or_default(request, "candle_type", "1d") domain: str = get_param_or_default(request, "domain", "IN") sync: str = get_param_or_default(request, "sync", "0") reload: str = get_param_or_default(request, "reload", "0") show_result: str = get_param_or_default(request, "result", "0") rkey = "indicator_history_{}".format(domain) result = dredis.getPickle(rkey) has_data = dredis.hasKey(rkey) # reload if reload == "1": if sync == "1": tasks.taskBuildIndicator(domain, candle_type) result = dredis.getPickle(rkey) return buildSuccess( "Got indicator", result if show_result == "1" else 'result is hidden') else: task_id = tasks.taskBuildIndicator.delay(domain, candle_type) if has_data: return buildSuccess( "Indicator is not yet ready", "Scheduled task id: /result/{}".format(task_id.id), ) else: return buildError( "Indicator is not yet ready", "Scheduled task id: /result/{}".format(task_id.id), ) # No data if result is None: # submit task task_id = tasks.taskBuildIndicator.delay(domain, candle_type) return buildError("Indicator is not yet ready", "Scheduled task id: /result/{}".format(task_id.id)) # Reload on time # mayUpdateStateData(domain, candle_type) return buildSuccess("Got indicator", result if show_result == "1" else 'result is hidden')
def market(): "status of the app" # Get the data for which doamin ? domain: str = get_param_or_default(request, "domain", "IN") # Do you want to return data and submit job to reload ? reload: str = get_param_or_default(request, "reload", "0") # Do you want to reload data on celeery in in this process for debugging? sync: str = get_param_or_default(request, "sync", "0") return buildSuccess("Status Ok", dglobaldata.getLatestMarketData(domain, reload, sync))
def Screen(): dglobaldata.checkLoadLatestData() domain = get_param_or_default(request, 'domain', "IN") result = dfilter.performScreen( domain, get_param_or_throw(request, 'filter'), str_to_list(get_param_or_default(request, 'columns', ''))) return buildSuccess(msg='Here is the list of Stocks', out={ "result": result['result'], "timestamp": dglobaldata.getLastUpdatedTimeStamp(domain), 'error': result['last_error'] })
def index() -> Response: task_id = None if request.method == 'POST': task_id = tasks.simple_task.delay(request.form.get('message')) return buildSuccess("task submitted", {"status_url": "/result/{}".format(task_id)})
def timestamp(): " Just return the timestamp " domain: str = get_param_or_default(request, "domain", "IN") return buildSuccess( "Tiemstamp of server data retunrned", {"timestamp": dglobaldata.getLastUpdatedTimeStamp(domain)})
def redis(): key: str = get_param_or_default(request, "key", "") result = dredis.getPickle(key, {}) return buildSuccess("Saved redis data", result)