Skip to content

Commit

Permalink
namespaces/daemon: namespace modifications to complement the build re…
Browse files Browse the repository at this point in the history
…port implementation

Also add a method to update specific attributes of a document for more flexeblity

Signed-off-by: ZorEl212 <[email protected]>
  • Loading branch information
ZorEl212 committed Nov 4, 2024
1 parent e78fa61 commit 7da7044
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions models/engine/mongodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ def update(self, obj):
collection.update_one({'id': obj.id}, {'$set': obj.to_dict()})
return obj

def update_attrib(self, obj, attr, value):
collection = self.database[obj.cls_name]
result = collection.update_one({'id': obj.id}, {'$set': {attr: value}})
return True if result.modified_count > 0 else False

def close(self):
self.client.close()

Expand Down
6 changes: 3 additions & 3 deletions socket_namespaces/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from models.build import Build
from models.user import User

import asyncio

class Daemon(Common, Namespace):
def on_builds_report(self, sid, data):
Expand All @@ -15,8 +14,9 @@ def on_builds_report(self, sid, data):
return
build_id = data.get("build_id")
print(f"Received builds report from {sid}: {data}")
config.publish('build_reports', json.dumps(data))

build = storage.get('Build', build_id)
retval =storage.update_attrib(build, 'report', data.get('data'))

def on_add_build(self, sid, data):
if not self.check_auth(sid):
self.handle_unauthorized(sid)
Expand Down

0 comments on commit 7da7044

Please sign in to comment.