Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): implement events #18

Open
wants to merge 1 commit into
base: feat/spotfleet-mgmt-ui
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions DeadlineStack/spotfleet-mgmt-ui/server/services/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
BACKUP_CREATED = "BACKUP_CREATED"
BACKUP_DELETED = "BACKUP_DELETED"
FLEET_CREATED = "FLEET_CREATED"
FLEET_DELETED = "FLEET_DELETED"
FLEET_UPDATED = "FLEET_UPDATED"
ROLLBACK_REQUESTED = "ROLLBACK_REQUESTED"
47 changes: 47 additions & 0 deletions DeadlineStack/spotfleet-mgmt-ui/server/services/events.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from database.dynamo_db import DynamoDB
import boto3
import uuid


class EventsException(Exception):
pass


class Events:
def __init__(self):
self._table_name = 'events'
self.dynamodb = DynamoDB(self._table_name)
self.local_dynamodb = boto3.resource(
'dynamodb', endpoint_url="http://localhost:8000")
if not self._table_name in self.local_dynamodb.meta.client.list_tables()['TableNames']:
self.create_event_table()

def create_event_table(self):
self.local_dynamodb.create_table(
TableName=self._table_name,
KeySchema=[
{
'AttributeName': 'Hashkey',
'KeyType': 'HASH'
}],
AttributeDefinitions=[
{
'AttributeName': 'Hashkey',
'AttributeType': 'S'
}],
BillingMode='PAY_PER_REQUEST'
)

def new_event(self, event_type: str, original_path: str, backup_path: str, json_data: dict):
try:
self.dynamodb.put_item_db({
'Hashkey': str(uuid.uuid4()),
'event_type': event_type,
'original_path': original_path,
'backup_path': backup_path,
'json_data': json_data
}, db_client=self.local_dynamodb)

except Exception as e:
raise EventsException(
f"Error processing event: {str(e)}")
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from ..events import Events


class TestEvents:
pass