Skip to content

Commit

Permalink
Refactor name of timestamp_server to timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
tnaccarato committed Apr 16, 2024
1 parent 58bb9f3 commit 9e93967
Show file tree
Hide file tree
Showing 16 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion custom_admin/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.urls import reverse
from payapp.models import Account
from register.forms import UserForm
from timestamp_server import thrift_server
from timestamp import thrift_server


class CustomAdminViewTests(TestCase):
Expand Down
2 changes: 1 addition & 1 deletion payapp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from gen_py.timestamp_service import TimestampService
from timestamp_server.timestamp_client import ThriftTimestampClient
from timestamp.thrift_client import ThriftTimestampClient


class ThriftTimestampField(models.DateTimeField):
Expand Down
2 changes: 1 addition & 1 deletion payapp/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.urls import reverse
from django.contrib.auth.models import User, Group
from payapp.models import Account, Request, Notification
from timestamp_server import thrift_server
from timestamp import thrift_server

class PayAppViewTests(TestCase):
@classmethod
Expand Down
2 changes: 1 addition & 1 deletion payapp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from payapp.models import Transfer, Account, Request, Notification
from webapps2024 import settings
from django.db import transaction
from timestamp_server.timestamp_client import ThriftTimestampClient
from timestamp.thrift_client import ThriftTimestampClient

currency_symbols = {
'USD': '$',
Expand Down
2 changes: 1 addition & 1 deletion register/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.apps import AppConfig
from django.db.models.signals import post_migrate
from register import create_admin_account
from timestamp_server import thrift_server
from timestamp import thrift_server


class RegisterConfig(AppConfig):
Expand Down
2 changes: 1 addition & 1 deletion register/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.contrib.auth.models import User, Group
from register.forms import UserForm, LoginForm
from payapp.utils import convert_currency
from timestamp_server import thrift_server
from timestamp import thrift_server


class UserViewTests(TestCase):
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion timestamp_server/apps.py → timestamp/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

class TimestampServerConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'timestamp_server'
name = 'timestamp'
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,20 @@ def __init__(self, host='localhost', port=9090):
def get_current_timestamp(self):
"""Fetch the current timestamp from the Thrift server."""
try:
# Create a Thrift client to connect to the server
transport = TSocket.TSocket(self.host, self.port)
transport = TTransport.TBufferedTransport(transport)
protocol = TBinaryProtocol.TBinaryProtocol(transport)
client = TimestampService.Client(protocol)
# Open the connection to the server
transport.open()
# Fetch the current timestamp from the server
timestamp = client.getCurrentTimestamp()
# Close the connection to the server
transport.close()
return timestamp

# Handle any exceptions that occur during the process
except Exception as e:
print("An error occurred while fetching the timestamp:", e)
return None
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,29 @@

class TimestampHandler:
def getCurrentTimestamp(self):
"""Return the current timestamp in the format 'YYYY-MM-DD HH:MM:SS'"""
return datetime.now().strftime("%Y-%m-%d %H:%M:%S")

def start_thrift_server():
"""Start the Thrift server and serve requests indefinitely."""
# Declare the global variables
global server
global server_running
# Create the Thrift server
handler = TimestampHandler()
processor = TimestampService.Processor(handler)
transport = TSocket.TServerSocket(port=9090)
tfactory = TTransport.TBufferedTransportFactory()
pfactory = TBinaryProtocol.TBinaryProtocolFactory()

# Start the server loop
server = TServer.TSimpleServer(processor, transport, tfactory, pfactory)
print("Starting the Thrift server...")
while server_running:
server.serve()

def stop_thrift_server():
"""Stop the Thrift server."""
global server_running
server_running = False

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion webapps2024/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"custom_admin.apps.AdminConfig",
"conversion",
"django_extensions",
"timestamp_server.apps.TimestampServerConfig"
"timestamp.apps.TimestampServerConfig"
]

MIDDLEWARE = [
Expand Down

0 comments on commit 9e93967

Please sign in to comment.