Commit 6bfb7ac4 authored by tammam.alsoleman's avatar tammam.alsoleman

Last update

parent 484f833c
import sys
import os
# إضافة مسار المجلد generated إلى Python path
sys.path.append(os.path.join(os.path.dirname(__file__), 'generated'))
......@@ -102,7 +101,7 @@ def main():
client.get_history()
elif choice == "3":
print("👋 Goodbye!")
print("Goodbye!")
break
else:
......
......@@ -3,7 +3,6 @@ const protoLoader = require('@grpc/proto-loader');
const path = require('path');
const fs = require('fs').promises;
// تحميل بروتوكول gRPC
const PROTO_PATH = path.join(__dirname, '../proto/calculator.proto');
const packageDefinition = protoLoader.loadSync(PROTO_PATH, {
keepCase: true,
......@@ -14,11 +13,10 @@ const packageDefinition = protoLoader.loadSync(PROTO_PATH, {
});
const calculatorProto = grpc.loadPackageDefinition(packageDefinition).calculator;
// تخزين العمليات
let operations = [];
class MultiplicationService {
// دالة الضرب
multiply(call, callback) {
const { a, b } = call.request;
const result = a * b;
......@@ -32,10 +30,8 @@ class MultiplicationService {
timestamp
};
// حفظ العملية في الذاكرة
operations.push(operation);
// حفظ في ملف السجل
this.logToFile(operation);
console.log(` Multiplication operation: ${a} × ${b} = ${result}`);
......@@ -46,7 +42,6 @@ class MultiplicationService {
});
}
// دالة جلب السجل (Streaming)
getOperationHistory(call) {
console.log(' Sending operation history...');
......@@ -55,12 +50,10 @@ class MultiplicationService {
operations: operations
};
// إرسال السجل
call.write(history);
call.end();
}
// دالة حفظ في ملف
async logToFile(operation) {
try {
const logEntry = `[${operation.timestamp}] ${operation.type}: ${operation.a} × ${operation.b} = ${operation.result}\n`;
......@@ -75,13 +68,11 @@ function main() {
const server = new grpc.Server();
const multiplicationService = new MultiplicationService();
// تسجيل الخدمة
server.addService(calculatorProto.Calculator.service, {
Multiply: multiplicationService.multiply.bind(multiplicationService),
GetOperationHistory: multiplicationService.getOperationHistory.bind(multiplicationService)
});
// بدء الخادم
server.bindAsync(
'0.0.0.0:50053',
grpc.ServerCredentials.createInsecure(),
......@@ -97,7 +88,6 @@ function main() {
);
}
// معالجة إغلاق التطبيق بشكل أنيق
process.on('SIGINT', () => {
console.log('\n Shutting down Multiplication Service...');
process.exit(0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment