def schedule_drives_get_data(drive_account, organization):
    "Schedules Lambda function to get Drive data and add to S3."

    # caracal_production_get_static_google_google_sheet_data
    function_name = f'caracal_{settings.STAGE.lower()}_get_static_{drive_account.provider}_{drive_account.file_type}_data'
    lambda_function = _lambda.get_lambda_function(function_name)

    file_type, provider = drive_account.file_type, drive_account.provider
    short_name = organization.short_name

    rule_name = _get_drives_get_data_rule_name(
        short_name=short_name,
        provider=provider,
        file_type=file_type,
        stage=settings.STAGE,
        drive_account_uid=drive_account.uid
    )

    get_data_rule_input = {
        'account_uid': str(drive_account.uid)
    }

    _lambda.schedule_lambda_function(
        fn_arn=lambda_function['arn'],
        fn_name=lambda_function['name'],
        rule_input=get_data_rule_input,
        rule_name=rule_name,
        rate_minutes=settings.COLLARS_GET_DATA_RATE_MINUTES
    )

    return {
        'rule_name': rule_name
    }
Exemple #2
0
def schedule_collars_get_data(data, collar_account, organization):

    species = data['type']
    provider = data['provider']

    get_data_rule_input = dict()
    get_data_rule_input['account_uid'] = str(collar_account.uid)

    if provider == 'orbcomm':
        get_data_rule_input['orbcomm_timezone'] = 2 # fixme: send offset integer data['orbcomm_timezone']
        get_data_rule_input['orbcomm_company_id'] = data['orbcomm_company_id']

    elif provider == 'savannah_tracking':
        get_data_rule_input['savannah_tracking_username'] = data['savannah_tracking_username']
        get_data_rule_input['savannah_tracking_password'] = data['savannah_tracking_password']

    else:
        return {
            'error': 'unknown_provider'
        }

    function_name = f'caracal_{settings.STAGE.lower()}_get_realtime_{provider}_data'
    lambda_function = _lambda.get_lambda_function(function_name)

    short_name = organization.short_name
    rule_name = get_collars_get_data_rule_name(short_name, settings.STAGE, provider, species, collar_account.uid)

    _lambda.schedule_lambda_function(lambda_function['arn'], lambda_function['name'], get_data_rule_input,
                                 rule_name, settings.COLLARS_GET_DATA_RATE_MINUTES)

    return {
        'rule_name': rule_name
    }
Exemple #3
0
def _schedule_source_kml(source, organization):
    "docs"

    function_name = f"caracal_{settings.STAGE.lower()}_update_custom_source_kml"
    update_kml_function = _lambda.get_lambda_function(function_name)

    rule_names = list()
    for period in settings.KML_PERIOD_HOURS:

        rate_minutes = int(period / 2.5)

        update_kml_input = {
            "source_uid": str(source.uid),
            "period_hours": period
        }

        short_name = organization.short_name
        rule_name = _get_source_update_kml_rule_name(short_name, source.uid,
                                                     settings.STAGE, period)
        rule_names.append(rule_name)

        _lambda.schedule_lambda_function(
            fn_arn=update_kml_function["arn"],
            fn_name=update_kml_function["name"],
            rule_input=update_kml_input,
            rule_name=rule_name,
            rate_minutes=rate_minutes,
        )

    source.cloudwatch_update_kml_rule_names = ",".join(rule_names)
    source.save()
Exemple #4
0
def _schedule_jackal_kml(network, organization):

    function_name = f"caracal_{settings.STAGE.lower()}_update_jackal_kml"
    update_kml_function = _lambda.get_lambda_function(function_name)

    rule_names = list()
    for period in settings.KML_PERIOD_HOURS:

        rate_minutes = int(period / 2.5)  # longer for larger periods

        update_kml_input = {
            "jackal_network_uid": str(network.uid),
            "period_hours": period,
        }

        rule_name = _get_jackal_update_kml_rule_name(
            short_name=organization.short_name,
            jackal_network_uid=network.uid,
            stage=settings.STAGE,
            period=period)

        rule_names.append(rule_name)

        _lambda.schedule_lambda_function(fn_arn=update_kml_function["arn"],
                                         fn_name=update_kml_function["name"],
                                         rule_input=update_kml_input,
                                         rule_name=rule_name,
                                         rate_minutes=rate_minutes)

    network.cloudwatch_update_kml_rule_names = ",".join(rule_names)
    network.save()
def _schedule_drives_agol(drive_account, connection, organization):
    "Schedules Lambda function that gets Drive data from S3 and updates AGOL."

    function_name = f'caracal_{settings.STAGE.lower()}_update_static_agol'
    update_agol_function = _lambda.get_lambda_function(function_name)

    update_agol_input = {
        'connection_uid': str(connection.uid),
    }

    short_name = organization.short_name
    rule_name = _get_drives_update_agol_rule_name(short_name, drive_account.uid, settings.STAGE, drive_account.provider,
                                                 drive_account.file_type)

    _lambda.schedule_lambda_function(update_agol_function['arn'], update_agol_function['name'], update_agol_input,
                                 rule_name, settings.AGOL_UPDATE_RATE_MINUTES)

    connection.cloudwatch_update_rule_name = rule_name
    connection.save()
def _schedule_drives_kml(drive_account, organization):
    "Schedules Lambda function that gets Drive data from S3 and creates KML."

    function_name = f'caracal_{settings.STAGE.lower()}_update_static_kml'
    update_kml_function = _lambda.get_lambda_function(function_name)

    update_kml_input = {
        'drive_account_uid': str(drive_account.uid),
    }

    short_name = organization.short_name
    rule_name = _get_drives_update_kml_rule_name(short_name, drive_account.uid, settings.STAGE, drive_account.provider,
                                                drive_account.file_type)
    _lambda.schedule_lambda_function(update_kml_function['arn'], update_kml_function['name'], update_kml_input,
                                 rule_name, settings.DRIVE_KML_UPDATE_RATE_MINUTES)

    drive_account.cloudwatch_update_kml_rule_names = rule_name
    drive_account.save()

    
Exemple #7
0
def _schedule_source_agol(source, connection, organization):
    "docs"

    function_name = f"caracal_{settings.STAGE.lower()}_update_custom_source_agol"
    update_agol_function = _lambda.get_lambda_function(function_name)

    update_agol_input = {
        "connection_uid": str(connection.uid),
    }

    short_name = organization.short_name
    rule_name = _get_source_update_agol_rule_name(short_name, source.uid,
                                                  settings.STAGE)

    _lambda.schedule_lambda_function(
        fn_arn=update_agol_function["arn"],
        fn_name=update_agol_function["name"],
        rule_input=update_agol_input,
        rule_name=rule_name,
        rate_minutes=settings.AGOL_UPDATE_RATE_MINUTES)

    connection.cloudwatch_update_rule_name = rule_name
    connection.save()
Exemple #8
0
def schedule_jackal_excel(network, organization):

    function_name = f"caracal_{settings.STAGE.lower()}_create_jackal_excel"
    create_excel_function = _lambda.get_lambda_function(function_name)

    create_excel_input = {
        "network_uid": str(network.uid),
    }

    rule_name = _get_jackal_create_excel_rule_name(
        short_name=organization.short_name,
        jackal_network_uid=network.uid,
        stage=settings.STAGE)

    _lambda.schedule_lambda_function(
        fn_arn=create_excel_function["arn"],
        fn_name=create_excel_function["name"],
        rule_input=create_excel_input,
        rule_name=rule_name,
        rate_minutes=settings.JACKAL_EXCEL_UPDATE_RATE_MINTES)

    network.cloudwatch_update_excel_rule_name = rule_name
    network.save()
Exemple #9
0
def _schedule_update_jackal_agol(network, connection, organization):

    function_name = f"caracal_{settings.STAGE.lower()}_update_jackal_agol"
    update_agol_function = _lambda.get_lambda_function(function_name)

    update_agol_input = {
        "connection_uid": str(connection.uid),
    }

    rule_name = _get_jackal_update_agol_rule_name(
        short_name=organization.short_name,
        jackal_network_uid=network.uid,
        stage=settings.STAGE)

    _lambda.schedule_lambda_function(
        fn_arn=update_agol_function["arn"],
        fn_name=update_agol_function["name"],
        rule_input=update_agol_input,
        rule_name=rule_name,
        rate_minutes=settings.AGOL_UPDATE_RATE_MINUTES)

    connection.cloudwatch_update_rule_name = rule_name
    connection.save()