cycls 0.0.2.18__tar.gz → 0.0.2.19__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cycls
3
- Version: 0.0.2.18
3
+ Version: 0.0.2.19
4
4
  Summary: Cycls SDK
5
5
  Author: Mohammed Jamal
6
6
  Author-email: mj@cycls.com
@@ -20,6 +20,7 @@ class Message(BaseModel):
20
20
  id: str
21
21
  history: Optional[List[Dict[str, str]]] = None
22
22
 
23
+ # too dirty
23
24
  def find_available_port(start_port):
24
25
  port = start_port
25
26
  while True:
@@ -29,7 +30,6 @@ def find_available_port(start_port):
29
30
  port += 1
30
31
 
31
32
  import asyncssh, asyncio
32
-
33
33
  async def create_ssh_tunnel(x,y,z='tuns.sh'):
34
34
  try:
35
35
  async with asyncssh.connect(z,client_keys=[key_path],known_hosts=None) as conn:
@@ -45,17 +45,16 @@ def register(handles, network, url, mode):
45
45
  response = client.post(f"{network}/register", json={"handles":handles, "url":url, "mode":mode})
46
46
  if response.status_code==200:
47
47
  data = (response.json()).get("content")
48
- for i in data:print(f"✦/✧ {i[0]} | {network}/{i[1]}")
48
+ for i in data:
49
+ if i[0]=="new":
50
+ print(f"✦/✧ {i[0]} | {network}/{i[1]}")
51
+ else:
52
+ print(f"✦/✧ {i[0]} | {network}/{i[1]}")
49
53
  else:
50
54
  print("✦/✧ failed to register ⚠️")
51
55
  except Exception as e:
52
56
  print(f"An error occurred: {e}")
53
57
 
54
- async def run_server(x,y):
55
- config = uvicorn.Config(x, host="127.0.0.1", port=y, log_level="error") # loop="asyncio"
56
- server = uvicorn.Server(config)
57
- await server.serve()
58
-
59
58
  class Cycls:
60
59
  def __init__(self, url="", network="https://cycls.com", port=find_available_port(8001)):
61
60
  import uuid
@@ -75,7 +74,7 @@ class Cycls:
75
74
  def sync_wrapper(*args, **kwargs):
76
75
  return StreamingResponse(func(*args, **kwargs))
77
76
  wrapper = async_wrapper if inspect.iscoroutinefunction(func) else sync_wrapper
78
- self.apps["@"+handle] = wrapper
77
+ self.apps[handle] = wrapper
79
78
  return wrapper
80
79
  return decorator
81
80
 
@@ -90,9 +89,19 @@ class Cycls:
90
89
 
91
90
  def push(self):
92
91
  self.server.post("/gateway")(self.gateway)
93
- asyncio.run(self.publish())
92
+ @self.server.on_event("startup")
93
+ def startup_event():
94
+ asyncio.create_task(create_ssh_tunnel(f"{self.subdomain}-cycls", self.port))
95
+
96
+ self.publish()
97
+
98
+ try:
99
+ uvicorn.run(self.server, host="127.0.0.1", port=self.port, log_level="error")
100
+ except KeyboardInterrupt:
101
+ print(f"\n✦/✧ exit | done")
94
102
 
95
- async def publish(self):
103
+ def publish(self):
104
+ # prod catch is too dirty
96
105
  prod=False
97
106
  if self.url != "":
98
107
  prod=True
@@ -104,21 +113,6 @@ class Cycls:
104
113
  else:
105
114
  self.url = f"http://{self.subdomain}-cycls.tuns.sh"
106
115
  print("✦/✧","mode | development")
107
- # print("✦/✧",f"url {self.url}")
108
116
  register(list(self.apps.keys()), self.network, self.url+"/gateway", "dev")
109
- t1 = asyncio.create_task(create_ssh_tunnel(f"{self.subdomain}-cycls", self.port))
110
-
111
- t2 = asyncio.create_task(run_server(self.server,self.port))
112
-
113
- try:
114
- if not prod:
115
- await asyncio.gather(t1, t2)
116
- else:
117
- await asyncio.gather(t2)
118
- except KeyboardInterrupt:
119
- # print("🔥")
120
- tasks = asyncio.all_tasks()
121
- for task in tasks:
122
- task.cancel()
123
-
117
+
124
118
  # poetry publish --build
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "cycls"
3
- version = "0.0.2.18"
3
+ version = "0.0.2.19"
4
4
 
5
5
  packages = [{ include = "cycls" }]
6
6
  description = "Cycls SDK"
File without changes
File without changes
File without changes