Skip to content

Commit

Permalink
v1.2.6
Browse files Browse the repository at this point in the history
Signed-off-by: Tim <[email protected]>
  • Loading branch information
TimMcCool authored Jun 18, 2023
1 parent ce4eca3 commit 8d73393
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
7 changes: 6 additions & 1 deletion scratchattach/_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def __init__(self, *, project_id, username="python", session_id=None, cloud_host
self.project_id = int(project_id)
except ValueError: #non-numeric project id (possible on turbowarp's cloud server)
self.project_id = str(project_id)
self._ratelimited_until = 0#deals with the 0.1 second rate limit for cloud variable sets
self._ratelimited_until = 0 #deals with the 0.1 second rate limit for cloud variable sets
self._connect_timestamp = 0 #timestamp of when the cloud connection was opened
self.websocket = websocket.WebSocket()
self._no_reconnect = False
self._connect(cloud_host=cloud_host)
Expand Down Expand Up @@ -86,6 +87,7 @@ def _connect(self, *, cloud_host):
)
except Exception:
raise(_exceptions.ConnectionError)
self._connect_timestamp = time.time()

def set_var(self, variable, value):
variable = variable.replace("☁ ", "")
Expand Down Expand Up @@ -142,6 +144,7 @@ def _connect(self, *, cloud_host):
)
except Exception:
raise(_exceptions.ConnectionError)
self._connect_timestamp = time.time()

def get_cloud(self, variable):
try:
Expand Down Expand Up @@ -318,6 +321,8 @@ def _update(self):
while True:
try:
data = self.connection.websocket.recv().split('\n')
if len(data) > 1 and time.time() < self.connection._connect_timestamp + 0.5:
continue
result = []
for i in data:
try:
Expand Down
12 changes: 12 additions & 0 deletions scratchattach/_cloud_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,18 @@ def get_timestamp(self):

return self.last_timestamp

def get_exact_timestamp(self):

logs = _cloud.get_cloud_logs(self.project_id,
filter_by_var_named="TO_HOST")
activity = list(
filter(lambda x: "." + self.last_request_id in x["value"],
logs))
if len(activity) > 0:
return activity[0]["timestamp"]
else:
return None

def _respond(self, request_id, response, limit, *, validation=2222):

if self.idle_since + 8 < time.time() or self.force_reconnect:
Expand Down

0 comments on commit 8d73393

Please sign in to comment.