Improved UI feedback on connections, sync, and use of tickets.
This commit is contained in:
parent
c4a3e6c948
commit
d7f953b907
4 changed files with 44 additions and 17 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
from core.observers.Notifications import Notifications, EventType
|
||||||
from core.services.sync import legacy_insert
|
from core.services.sync import legacy_insert
|
||||||
from core.models.manage.session_management import init_session, close_session
|
from core.models.manage.session_management import init_session, close_session
|
||||||
from core.services.sync.sync_service import coordinate_cache_sync, save_metadata
|
from core.services.sync.sync_service import coordinate_cache_sync, save_metadata
|
||||||
|
|
@ -83,7 +84,8 @@ def new_sync(client_observer: ClientObserver, connection_observer: ConnectionObs
|
||||||
# Outright Error:
|
# Outright Error:
|
||||||
if not metadata_result["success"]:
|
if not metadata_result["success"]:
|
||||||
error_msg = metadata_result["error"]
|
error_msg = metadata_result["error"]
|
||||||
client_observer.notify('synchronizing', f'Error! {error_msg}')
|
# client_observer.notify('synchronizing', f'Error! {error_msg}')
|
||||||
|
Notifications.emit(EventType.STATUS_UPDATE, f'Error! {error_msg}')
|
||||||
return Result(valid=False)
|
return Result(valid=False)
|
||||||
|
|
||||||
# Nothing changed if the 'changed_tables' variable does NOT exist
|
# Nothing changed if the 'changed_tables' variable does NOT exist
|
||||||
|
|
@ -104,9 +106,13 @@ def new_sync(client_observer: ClientObserver, connection_observer: ConnectionObs
|
||||||
# CHECK ON CHANGED TABLES
|
# CHECK ON CHANGED TABLES
|
||||||
if not changed_tables:
|
if not changed_tables:
|
||||||
client_observer.notify('synchronized')
|
client_observer.notify('synchronized')
|
||||||
|
notification = "Sync Complete. (already up to date)"
|
||||||
|
Notifications.emit(EventType.STATUS_UPDATE, notification)
|
||||||
return Result(valid=True)
|
return Result(valid=True)
|
||||||
|
|
||||||
# We only make it past this point if there's New Data
|
# We only make it past this point if there's New Data
|
||||||
|
notification = "Fetching Data.."
|
||||||
|
Notifications.emit(EventType.STATUS_UPDATE, notification)
|
||||||
|
|
||||||
####################################
|
####################################
|
||||||
# API CALLS: GET NEW DATA IN BULK
|
# API CALLS: GET NEW DATA IN BULK
|
||||||
|
|
@ -120,7 +126,9 @@ def new_sync(client_observer: ClientObserver, connection_observer: ConnectionObs
|
||||||
if not results.valid:
|
if not results.valid:
|
||||||
error_msg = f"Sync failed! {results.error_type}"
|
error_msg = f"Sync failed! {results.error_type}"
|
||||||
logger.error(f"{error_msg} {results.message}")
|
logger.error(f"{error_msg} {results.message}")
|
||||||
client_observer.notify('synchronizing', f'Error! {error_msg}')
|
notification = f'Error! {error_msg}'
|
||||||
|
# client_observer.notify('synchronizing', notification)
|
||||||
|
Notifications.emit(EventType.STATUS_UPDATE, notification)
|
||||||
return Result(valid=False)
|
return Result(valid=False)
|
||||||
|
|
||||||
quantity_of_entries = len(results.data)
|
quantity_of_entries = len(results.data)
|
||||||
|
|
@ -149,7 +157,9 @@ def new_sync(client_observer: ClientObserver, connection_observer: ConnectionObs
|
||||||
|
|
||||||
if each_insert.valid:
|
if each_insert.valid:
|
||||||
logger.info(f"Success with insert of {key}")
|
logger.info(f"Success with insert of {key}")
|
||||||
client_observer.notify('synchronizing', f'Inserted {key}')
|
notification = f'Inserted {key}'
|
||||||
|
Notifications.emit(EventType.STATUS_UPDATE, notification)
|
||||||
|
# client_observer.notify('synchronizing', f'Inserted {key}')
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
skipped.append(key)
|
skipped.append(key)
|
||||||
|
|
@ -171,7 +181,9 @@ def new_sync(client_observer: ClientObserver, connection_observer: ConnectionObs
|
||||||
client_observer.notify('synchronized', "Fetch & Save Complete!")
|
client_observer.notify('synchronized', "Fetch & Save Complete!")
|
||||||
save_successful = save_metadata(filtered_metadata)
|
save_successful = save_metadata(filtered_metadata)
|
||||||
if save_successful:
|
if save_successful:
|
||||||
return Result(valid=True, message="Finshed sync.")
|
notification = "Finshed sync."
|
||||||
|
Notifications.emit(EventType.STATUS_UPDATE, notification)
|
||||||
|
return Result(valid=True, message=notification)
|
||||||
else:
|
else:
|
||||||
error_msg = "Finshed sync, but had issues with the saving of metadata for next time."
|
error_msg = "Finshed sync, but had issues with the saving of metadata for next time."
|
||||||
logger.error(error_msg)
|
logger.error(error_msg)
|
||||||
|
|
@ -179,13 +191,15 @@ def new_sync(client_observer: ClientObserver, connection_observer: ConnectionObs
|
||||||
|
|
||||||
elif total_skipped < quantity_of_entries:
|
elif total_skipped < quantity_of_entries:
|
||||||
error_msg = f"Partial Success. {total_skipped} skipped."
|
error_msg = f"Partial Success. {total_skipped} skipped."
|
||||||
client_observer.notify('synchronized', error_msg)
|
# client_observer.notify('synchronized', error_msg)
|
||||||
|
Notifications.emit(EventType.STATUS_UPDATE, error_msg)
|
||||||
return Result(valid=True, data=skipped, message=error_msg)
|
return Result(valid=True, data=skipped, message=error_msg)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
error_msg = f"Sync Failed. All {total_skipped} entries were skipped!"
|
error_msg = f"Sync Failed. All {total_skipped} entries were skipped!"
|
||||||
client_observer.notify('synchronized', error_msg)
|
# client_observer.notify('synchronized', error_msg)
|
||||||
return Result(valid=False, data=skipped, message="Complete Failure, all data failed to insert.")
|
Notifications.emit(EventType.STATUS_UPDATE, error_msg)
|
||||||
|
return Result(valid=False, data=skipped, message=error_msg)
|
||||||
|
|
||||||
|
|
||||||
def insert_data(
|
def insert_data(
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ def get_traceback_line(error) -> ErrorStack:
|
||||||
func_name, line_no, file_name = "Unknown", "Unknown", "Unknown"
|
func_name, line_no, file_name = "Unknown", "Unknown", "Unknown"
|
||||||
|
|
||||||
# Generate the user-facing message and the full formatted stacktrace
|
# Generate the user-facing message and the full formatted stacktrace
|
||||||
error_msg = f"Error in {func_name} at {file_name}:{line_no} -> {str(error)}"
|
error_msg = f"Error in function {func_name} in file {file_name} on line {line_no}. That error is: {str(error)}"
|
||||||
full_trace = "".join(traceback.format_exception(type(error), error, tb))
|
full_trace = "".join(traceback.format_exception(type(error), error, tb))
|
||||||
|
|
||||||
logger.error(error_msg)
|
logger.error(error_msg)
|
||||||
|
|
|
||||||
|
|
@ -124,7 +124,11 @@ def _cleanup_on_error(firewall_setting: bool, dns_setting: bool) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def _finish_function(final_result: Result) -> Result:
|
def _finish_success(final_result: Result, profile_id: int) -> Result:
|
||||||
|
Notifications.emit(EventType.SYSTEM_ENABLE, profile_id)
|
||||||
|
notification = "Connected."
|
||||||
|
Notifications.emit(EventType.STATUS_UPDATE, notification)
|
||||||
|
|
||||||
terminate_tor_connection()
|
terminate_tor_connection()
|
||||||
time.sleep(0.3)
|
time.sleep(0.3)
|
||||||
return final_result
|
return final_result
|
||||||
|
|
@ -277,13 +281,9 @@ def __establish_system_connection(
|
||||||
current_state.firewalled = firewall_tracker
|
current_state.firewalled = firewall_tracker
|
||||||
current_state.dns_set = did_dns_work
|
current_state.dns_set = did_dns_work
|
||||||
SystemStateController.update_or_create(current_state)
|
SystemStateController.update_or_create(current_state)
|
||||||
|
notification = "DNS Set Did Not Work."
|
||||||
if connection_observer:
|
|
||||||
connection_observer.notify("connected", "Confirmed")
|
|
||||||
|
|
||||||
Notifications.emit(EventType.SYSTEM_ENABLE, profile.id)
|
|
||||||
notification = "Connected."
|
|
||||||
Notifications.emit(EventType.STATUS_UPDATE, notification)
|
Notifications.emit(EventType.STATUS_UPDATE, notification)
|
||||||
|
|
||||||
return Result(valid=True, data=current_state)
|
return Result(valid=True, data=current_state)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -331,7 +331,7 @@ def establish_system_connection(
|
||||||
)
|
)
|
||||||
|
|
||||||
if connection_result.valid:
|
if connection_result.valid:
|
||||||
return _finish_function(connection_result)
|
return _finish_success(final_result=connection_result, profile_id=profile.id)
|
||||||
|
|
||||||
# If not valid, we treat it as a failure to trigger the except block logic
|
# If not valid, we treat it as a failure to trigger the except block logic
|
||||||
notification = f"{attempt} attempt failed.."
|
notification = f"{attempt} attempt failed.."
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ from typing import TYPE_CHECKING
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from essentials.observers.ConnectionObserver import ConnectionObserver
|
from essentials.observers.ConnectionObserver import ConnectionObserver
|
||||||
|
|
||||||
|
from core.observers.Notifications import Notifications, EventType
|
||||||
from core.services.subscriptions.subscriptions_by_protocol import save_billing_code
|
from core.services.subscriptions.subscriptions_by_protocol import save_billing_code
|
||||||
from core.utils.get_raw_string import get_raw_string
|
from core.utils.get_raw_string import get_raw_string
|
||||||
from core.observers.TicketObserver import TicketObserver
|
from core.observers.TicketObserver import TicketObserver
|
||||||
|
|
@ -39,6 +40,9 @@ def save_ticket_use(
|
||||||
which_ticket: int
|
which_ticket: int
|
||||||
) -> Result:
|
) -> Result:
|
||||||
|
|
||||||
|
notification = "Saving New Billing Code.."
|
||||||
|
Notifications.emit(EventType.STATUS_UPDATE, notification)
|
||||||
|
|
||||||
saved_for_profile = save_billing_code(
|
saved_for_profile = save_billing_code(
|
||||||
profile_id=profile_id,
|
profile_id=profile_id,
|
||||||
billing_code=billing_code,
|
billing_code=billing_code,
|
||||||
|
|
@ -58,9 +62,15 @@ def save_ticket_use(
|
||||||
return saved_for_profile # result object
|
return saved_for_profile # result object
|
||||||
|
|
||||||
if saved_ticket_tracker:
|
if saved_ticket_tracker:
|
||||||
|
notification = "It Worked! Got Fresh Identity."
|
||||||
|
Notifications.emit(EventType.STATUS_UPDATE, notification)
|
||||||
return Result(valid=True)
|
return Result(valid=True)
|
||||||
else:
|
else:
|
||||||
return Result(valid=False, error_type=ResultError.FILE_SYSTEM, message="Unable to update the ticket tracker that the ticket is used.")
|
notification = "File Error! Failed to Save New Billing Code"
|
||||||
|
Notifications.emit(EventType.STATUS_UPDATE, notification)
|
||||||
|
error_msg = f"Unable to update the ticket tracker with your new billing code of {billing_code}, and that the ticket is used."
|
||||||
|
logger.error(error_msg)
|
||||||
|
return Result(valid=False, error_type=ResultError.FILE_SYSTEM, message=error_msg)
|
||||||
|
|
||||||
|
|
||||||
def make_payload(which_ticket: int, which_location: int, protocol_choice: ProtocolChoice) -> Result:
|
def make_payload(which_ticket: int, which_location: int, protocol_choice: ProtocolChoice) -> Result:
|
||||||
|
|
@ -111,6 +121,9 @@ def use_ticket_orchestrator(
|
||||||
if None in PRE_REQS:
|
if None in PRE_REQS:
|
||||||
return Result(valid=False, error_type=ResultError.MISSING_DATA, message="You are missing the profile data to use a ticket with.")
|
return Result(valid=False, error_type=ResultError.MISSING_DATA, message="You are missing the profile data to use a ticket with.")
|
||||||
|
|
||||||
|
notification = f"Using Ticket {which_ticket} on {profile.name}"
|
||||||
|
Notifications.emit(EventType.STATUS_UPDATE, notification)
|
||||||
|
|
||||||
###################################
|
###################################
|
||||||
# FILTER TICKET DATA
|
# FILTER TICKET DATA
|
||||||
###################################
|
###################################
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue