-
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.
messing around with triggering the job
- Loading branch information
Showing
9 changed files
with
180 additions
and
69 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 |
---|---|---|
|
@@ -13,6 +13,7 @@ shhhh/ | |
# app data | ||
|
||
app_data/ | ||
db.sqlite | ||
|
||
# C extensions | ||
*.so | ||
|
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
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,46 +1,70 @@ | ||
from __future__ import annotations | ||
import typing | ||
import base64 | ||
|
||
import asyncio | ||
# import ray | ||
import strawberry | ||
from strawberry.scalars import JSON, Base64 | ||
from strawberry_sqlalchemy_mapper import strawberry_dataclass_from_model | ||
import orjson | ||
from redis_streamer import utils, ctx | ||
from . import streams | ||
from strawberry_sqlalchemy_mapper import StrawberrySQLAlchemyMapper | ||
from redis_streamer.config import * | ||
from redis_streamer.models import session, RecordingModel | ||
from redis_streamer.models import session, RecordingModel, get_recording, create_recording, end_recording, rename_recording, delete_recording | ||
from .. import recorder | ||
|
||
strawberry_sqlalchemy_mapper = StrawberrySQLAlchemyMapper() | ||
|
||
# ---------------------------------------------------------------------------- # | ||
# Queries # | ||
# ---------------------------------------------------------------------------- # | ||
|
||
@strawberry.type | ||
@strawberry_dataclass_from_model(RecordingModel) | ||
@strawberry_sqlalchemy_mapper.type(RecordingModel) | ||
class Recording: | ||
pass | ||
|
||
@strawberry.type | ||
class RecordingsQuery: | ||
class Recordings: | ||
@strawberry.field | ||
def recordings(self) -> typing.List[Recording]: | ||
return session.query(RecordingModel).all() | ||
|
||
@strawberry.field | ||
def recording(self, id: strawberry.ID) -> Recording: | ||
return session.query(RecordingModel).get(id) | ||
def recording(self, name: strawberry.ID) -> Recording: | ||
return session.query(RecordingModel).get(name) | ||
|
||
@strawberry.field | ||
async def current_recording(self) -> str|None: | ||
return await writer.current_recording() | ||
|
||
|
||
# writer = recorder.RecordingWriter.remote() | ||
writer = recorder.RecordingWriter() | ||
|
||
@strawberry.type | ||
class RecordingMutation: | ||
@strawberry.mutation | ||
async def start(self, device_id: str, meta: JSON) -> JSON: | ||
return | ||
async def start_recording(self, name: str='') -> JSON: | ||
name = create_recording(name) | ||
await writer.start(name) | ||
return get_recording(name).as_dict() | ||
|
||
@strawberry.mutation | ||
async def stop_recording(self) -> JSON: | ||
# name = ray.get(writer.get_current_recording_name.remote()) | ||
name = await writer.current_recording() | ||
print(name) | ||
if not name: | ||
raise RuntimeError("No recording running") | ||
print('before stop') | ||
await writer.stop() | ||
print('after stop') | ||
end_recording(name) | ||
return get_recording(name).as_dict() | ||
|
||
@strawberry.mutation | ||
async def stop(self, device_id: str, meta: JSON) -> JSON: | ||
return | ||
async def rename_recording(self, name: str, new_name: str) -> JSON: | ||
rename_recording(name, new_name) | ||
return get_recording(new_name).as_dict() | ||
|
||
@strawberry.mutation | ||
async def rename(self, device_id: str) -> JSON: | ||
return await disconnect_device(device_id) | ||
async def delete_recording(self, name: str) -> None: | ||
delete_recording(name) | ||
return |
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,19 +1,46 @@ | ||
import datetime | ||
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime | ||
from . import Base | ||
from . import Base, session | ||
|
||
class RecordingModel(Base): | ||
__tablename__ = "recordings" | ||
id: int = Column(Integer, primary_key=True, index=True) | ||
name: str = Column(String, nullable=True) | ||
start_time: DateTime = Column(DateTime, nullable=False) | ||
end_time: DateTime = Column(DateTime, nullable=False) | ||
name: str = Column(String, primary_key=True, index=True) | ||
start_time: DateTime = Column(DateTime, nullable=True) | ||
end_time: DateTime = Column(DateTime, nullable=True) | ||
device_name: str = Column(String, nullable=True) | ||
|
||
def as_dict(self): | ||
start = self.start_time | ||
end = self.end_time | ||
return { | ||
"id": self.id, | ||
"name": self.name, | ||
"start_time": self.start_time, | ||
"end_time": self.end_time, | ||
"start_time": start.isoformat() if start else None, | ||
"end_time": end.isoformat() if end else None, | ||
"device_name": self.device_name, | ||
} | ||
} | ||
|
||
|
||
|
||
def create_recording(name=''): | ||
start_time = datetime.datetime.now() | ||
name = name or start_time.strftime('%Y-%m-%dT%H-%M-%S') | ||
session.add(RecordingModel(name=name, start_time=start_time)) | ||
session.commit() | ||
return name | ||
|
||
def end_recording(name): | ||
session.query(RecordingModel).filter(RecordingModel.name == name).update({'end_time': datetime.datetime.now()}) | ||
session.commit() | ||
|
||
def get_recording(name): | ||
return session.query(RecordingModel).get(name) | ||
|
||
def rename_recording(old_name, new_name): | ||
rec = session.query(RecordingModel).filter(RecordingModel.name == old_name).update({'name': new_name}) | ||
# rec.name = new_name | ||
session.commit() | ||
|
||
def delete_recording(name): | ||
session.query(RecordingModel).filter(RecordingModel.name == name).delete() | ||
session.commit() | ||
|
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 |
---|---|---|
|
@@ -5,4 +5,7 @@ websockets | |
redis | ||
orjson | ||
gunicorn | ||
uvicorn | ||
uvicorn | ||
strawberry_sqlalchemy_mapper | ||
ray | ||
tqdm |