-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
720 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: Build and release | ||
run-name: Build and release ${{ inputs.version || github.ref_name }} | ||
on: | ||
push: | ||
tags: | ||
- v* | ||
workflow_dispatch: | ||
inputs: | ||
version: | ||
required: true | ||
type: string | ||
description: Version (vX.X.X.X) | ||
jobs: | ||
build-python-release: | ||
uses: shibijm/gh-actions-workflows/.github/workflows/build-python-release-preset-1.yml@master | ||
with: | ||
version: ${{ inputs.version || github.ref_name }} | ||
permissions: | ||
contents: write |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Copyright (c) 2018-2023 Shibi J M | ||
|
||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Affero General Public License, version 3, | ||
as published by the Free Software Foundation. | ||
|
||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Affero General Public License for more details. | ||
|
||
You should have received a copy of the GNU Affero General Public License | ||
along with this program. If not, see <https://www.gnu.org/licenses/>. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
from .WebSocketServer import WebSocketServer as WebSocketServer | ||
from .WebSocketController import WebSocketController as WebSocketController |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
from controllers import WebSocketServer | ||
from controllers import WebSocketController | ||
from models import User | ||
from utils import KeepAlive | ||
from utils.logging import logger | ||
from websockets.server import serve | ||
import asyncio | ||
import os | ||
|
||
isHeroku = "PORT" in os.environ | ||
port = int(os.environ["PORT"]) if isHeroku else 22334 | ||
|
||
if isHeroku: | ||
logger.info("Heroku detected, activating keep-alive mode") | ||
KeepAlive() | ||
|
||
port = int(os.environ["PORT"]) if "PORT" in os.environ else 22334 | ||
users: list[User] = [] | ||
webSocketController = WebSocketController(users) | ||
keepAliveUrl = os.environ.get("KEEPALIVE_URL") | ||
if keepAliveUrl: | ||
KeepAlive(keepAliveUrl, users) | ||
async def run() -> None: | ||
server = await serve(webSocketController.connectionHandler, None, port, ping_interval = None, ping_timeout = None) | ||
await server.wait_closed() | ||
logger.info("Starting WebSocket server on port %s", port) | ||
WebSocketServer(port) | ||
asyncio.run(run()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
from controllers import WebSocketServer | ||
from models import User | ||
import requests | ||
import threading | ||
import time | ||
|
||
class KeepAlive(threading.Thread): | ||
|
||
def __init__(self) -> None: | ||
def __init__(self, url: str, users: list[User]) -> None: | ||
super().__init__() | ||
self.url = url | ||
self.users = users | ||
self.daemon = True | ||
self.start() | ||
|
||
def run(self) -> None: | ||
while (True): | ||
time.sleep(900) | ||
if (len(WebSocketServer.users) > 0): | ||
requests.get("https://watchalong-s.herokuapp.com") | ||
time.sleep(600) | ||
if self.users: | ||
requests.get(self.url) |