<commit_before>"""
.. module: lemur.endpoints.cli
    :platform: Unix
    :copyright: (c) 2015 by Netflix Inc., see AUTHORS for more
    :license: Apache, see LICENSE for more details.
.. moduleauthor:: <NAME> <<EMAIL>>
"""
from flask_script import Manager

import arrow
from datetime import timedelta

from sqlalchemy import cast
from sqlalchemy_utils import ArrowType

from lemur import database
from lemur.extensions import metrics
from lemur.endpoints.models import Endpoint


manager = Manager(usage="Handles all endpoint related tasks.")


@manager.option('-ttl', '--time-to-live', type=int, dest='ttl', default=2, help='Time in hours, which endpoint has not been refreshed to remove the endpoint.')
def expire(ttl):
    """
    Removed all endpoints that have not been recently updated.
    """
    now = arrow.utcnow()
    expiration = now - timedelta(hours=ttl)
    endpoints = database.session_query(Endpoint).filter(cast(Endpoint.last_updated, ArrowType) <= expiration)

    for endpoint in endpoints:
        database.delete(endpoint)
        metrics.send('endpoint_expired', 'counter', 1)<commit_msg>Adding some additional output to expiration command. (#626)<commit_after>"""
.. module: lemur.endpoints.cli
    :platform: Unix
    :copyright: (c) 2015 by Netflix Inc., see AUTHORS for more
    :license: Apache, see LICENSE for more details.
.. moduleauthor:: <NAME> <<EMAIL>>
"""
from flask_script import Manager

import arrow
from datetime import timedelta

from sqlalchemy import cast
from sqlalchemy_utils import ArrowType

from lemur import database
from lemur.extensions import metrics
from lemur.endpoints.models import Endpoint


manager = Manager(usage="Handles all endpoint related tasks.")


@manager.option('-ttl', '--time-to-live', type=int, dest='ttl', default=2, help='Time in hours, which endpoint has not been refreshed to remove the endpoint.')
def expire(ttl):
    """
    Removed all endpoints that have not been recently updated.
    """
    print("[+] Staring expiration of old endpoints.")
    now = arrow.utcnow()
    expiration = now - timedelta(hours=ttl)
    endpoints = database.session_query(Endpoint).filter(cast(Endpoint.last_updated, ArrowType) <= expiration)

    for endpoint in endpoints:
        print("[!] Expiring endpoint: {name} Last Updated: {last_updated}".format(name=endpoint.name, last_updated=endpoint.last_updated))
        database.delete(endpoint)
        metrics.send('endpoint_expired', 'counter', 1)

    print("[+] Finished expiration.")
{'fraction_non_alphanumeric': 0.11142172523961662, 'fraction_numerical': 0.0059904153354632585, 'mean_word_length': 4.398706896551724, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2449002', 'n_tokens_mistral': 753, 'n_tokens_neox': 694, 'n_words': 237}