Пример #1
0
def service_load_dates() -> Tuple[datetime, datetime, datetime]:
    " returns flask app start time, Pyro4 service start time, and current time (all ET)"
    try:
        service = get_proxy()
        service_date = datetime.fromisoformat(service.load_date)
        return load_date, service_date, udatetime.now_as_eastern() 
    except Exception as ex:
        logger.exception(ex)
        return load_date, None, udatetime.now_as_eastern()
Пример #2
0
def current_time_and_phase() -> Tuple[datetime, str]:
    "get the current time (ET) and phase of the process given the hour"

    target_time = udatetime.now_as_eastern()

    hour = target_time.hour

    # note -- these are all just guesses on a mental model of 1 update per day. Josh
    phase = ""
    if hour < 10:
        phase = "inactive"
    elif hour < 12 + 2:
        phase = "prepare"  # preparing for run
    elif hour < 12 + 4:
        phase = "active"  # working on an update
    elif hour < 12 + 6:
        phase = "publish"  # getting close to publishing
    elif hour < 12 + 9:
        phase = "cleanup"  # cleanup from main run
    elif hour < 12 + 10:
        phase = "update"  # updating numbers for the day
    else:
        phase = "inactive"

    return target_time, phase
def is_out_of_date(log: ResultLog, cache_seconds: int) -> bool:
    " check if result is out-of-date"
    if log == None:
        logger.info("first run")
        return True
    dt = udatetime.now_as_eastern()
    delta = dt - log.loaded_at
    t = int(delta.total_seconds())
    if t > cache_seconds:
        logger.info(f"last-run {t:,}s ago -> rerun")
        return True
    else:
        logger.info(f"last-run at {t:,}s ago -> skip")
Пример #4
0
    def init_publish_date(self):

        # expect publish at 5PM ET, push at 12AM, 5PM, and 12PM
        #    publish means history updates
        #    push means current updates
        dt = udatetime.now_as_eastern()
        if dt.hour < 8:            
            dt = dt + timedelta(days=-1)
            dt_current = dt_history = dt_working = dt
            push_num = 3
        elif dt.hour < 12:
            dt_current = dt_history = dt + timedelta(days=-1)
            dt_working = dt
            push_num = 3
        elif dt.hour < 5:
            dt_history = dt + timedelta(days=-1)
            dt_current = dt_working = dt
            push_num = 1
        else:
            dt_history = dt + timedelta(days=-1)
            dt_current = dt_working = dt
            push_num = 2


        if 3 <= dt.hour <= 5:
            self.is_near_release = True
        elif 11 <= dt.hour <= 12:
            self.is_near_release = True
        else:
            self.is_near_release = False
        
        # working_date is the date for the spreadsheet  
        self.working_date =  dt_working
        self.working_date_int = dt_working.year * 10000 + dt_working.month * 100 + dt_working.day

        # publish_date is when history has been updated
        self.publish_date =  dt_history
        self.publish_date_int = dt_history.year * 10000 + dt_history.month * 100 + dt_history.day

        # push_date is when current has been updated
        self.push_date =  dt_current
        self.push_date_int = dt_current.year * 10000 + dt_current.month * 100 + dt_current.day

        # which push we are at for the current table
        self.push_num = push_num

        logger.info(f"dates: ")
        logger.info(f" working date is {self.working_date_int}")
        logger.info(f" push  date is {self.push_date_int}")
        logger.info(f" publish date is {self.publish_date_int}")
        logger.info(f" push num is {self.push_num}")
Пример #5
0
# A Flask Blueprint to support embedding checks as a library
#

import os
from flask import Blueprint, request, jsonify, Response, render_template
import json
from typing import Tuple
from datetime import datetime
from loguru import logger

from run_quality_service import get_proxy
import app.util.udatetime as udatetime

checks = Blueprint("checks", __name__, url_prefix='/checks')

load_date = udatetime.now_as_eastern()

def service_load_dates() -> Tuple[datetime, datetime, datetime]:
    " returns flask app start time, Pyro4 service start time, and current time (all ET)"
    try:
        service = get_proxy()
        service_date = datetime.fromisoformat(service.load_date)
        return load_date, service_date, udatetime.now_as_eastern() 
    except Exception as ex:
        logger.exception(ex)
        return load_date, None, udatetime.now_as_eastern()


@checks.route("/working.json", methods=["GET"])
def working_json():
    try:
Пример #6
0
    def __init__(self):
        self.loaded_at = udatetime.now_as_eastern()
        self.start = time.process_time_ns()

        self._messages: List[ResultLog] = []