Beispiel #1
0
from ticker.main_loop import Ticker


if get_environment() == "development":
    import ptvsd

    print("[Scheduler] debug mode")
    try:
        ptvsd.enable_attach(address=("0.0.0.0", 5680))
        ptvsd.wait_for_attach(8)
    except Exception as e:
        print(e)
        print("[Scheduler] ptvsd attach aborted")


load_credentials(decrypt_credentials(which=["*.env"]))

app = web.Application()
db_middleware = init_middleware(app)
app.middlewares.append(db_middleware)


async def persistent_session(app):
    app["PERSISTENT_SESSION"] = session = aiohttp.ClientSession()
    yield
    await session.close()


app.cleanup_ctx.append(persistent_session)

ticker = Ticker()
from pathlib import Path
from dotenv import load_dotenv

env_path = Path('.') / '.env'
load_dotenv(dotenv_path=env_path)

from secrets_management.manage import decrypt_credentials, load_credentials, get_environment

load_credentials(decrypt_credentials(which=['*.env']))

import asyncpg
from datetime import timedelta
from datetime import datetime
from utils.timeseries.timescale_utils import init_db, init_connection, get_pool

print("""=== Timescale REPL Loaded ===
To load TimescaleDB connection:
pool = await get_pool()
conn = await pool.acquire()
await conn.fetch(query, *params)
""")
from functools import partial
import asyncio
import json
from google.oauth2 import service_account
from google.cloud import bigquery
from secrets_management.manage import decrypt_credentials
from .abstract_source import AbstractSource

credfile = decrypt_credentials(which=['./.secrets/keyring.json'])
creds_json = json.loads(credfile[0])
creds = service_account.Credentials.from_service_account_info(creds_json)
bigquery_client = bigquery.Client(credentials=creds,
                                  project=creds_json['project_id'])

sql_query_get_intervals = r"""
with
  c as (select *,
    TIMESTAMP_ADD(queried_at, INTERVAL 3600 SECOND) as queried_end,
    max(TIMESTAMP_ADD(queried_at, INTERVAL 3600 SECOND)) over (order by queried_at rows between unbounded preceding and 1 preceding) as previous_max
    from `livewater.production.kunaTicksBTCUAH`
  )
select queried_at, 
    coalesce(lead(previous_max) over (order by queried_at),
   (select max(queried_end) from c)
               ) as queried_end
from c 
where previous_max < queried_at 
   or previous_max is null
order by queried_at desc
limit {limit}
"""
Beispiel #4
0
def cli(env):
    print(f'Encrypting env: {env}...')
    encrypt_credentials(env)
    print(f'Test loading env: {env}...')
    load_credentials(decrypt_credentials(env, which=['*.env']))
    print('Done.')
def main():
    load_credentials(decrypt_credentials(which=["*.env"]))
    asyncio.get_event_loop().run_until_complete(test_asyncpg())
Beispiel #6
0
def process_init():
    print(f"[init] Starting process for environment `{get_environment()}`")
    load_credentials(decrypt_credentials(which=["*.env"]))
    print("[init] Initializing middlewares...")
Beispiel #7
0
def cli(env):
    print(f"Encrypting env: {env}...")
    encrypt_credentials(env)
    print(f"Test loading env: {env}...")
    load_credentials(decrypt_credentials(env, which=["*.env"]))
    print("Done.")