This commit is contained in:
emmatveev 2024-12-08 15:33:34 +03:00
parent 8eda61e56b
commit 7c2fb7cd6e
4 changed files with 21 additions and 42 deletions

1
.gitignore vendored
View File

@ -119,3 +119,4 @@ GitHub.sublime-settings
.history
*pb2*
schemas

View File

@ -1,4 +1,6 @@
gen:
python -m grpc_tools.protoc --proto_path schemas --python_out=. --pyi_out=. --grpc_python_out=. ./schemas/tasks.proto
rm -rf schemas
python generator.py queues
python -m grpc_tools.protoc --proto_path schemas --python_out=. --pyi_out=. --grpc_python_out=. ./schemas/queues/tasks.proto
run:
python ./server.py

16
generator.py Normal file
View File

@ -0,0 +1,16 @@
import json
import urllib.request
import sys
import os
arg = sys.argv[-1]
response = urllib.request.urlopen(f'https://platform.sprinthub.ru/schemas/get?project={arg}').read()
data = json.loads(response)
os.mkdir('schemas')
os.mkdir(f'schemas/{arg}')
for key, value in data.items():
with open(f'schemas/{arg}/{key}', 'w+') as fp:
fp.write(value)

View File

@ -1,40 +0,0 @@
syntax = "proto3";
package queues;
import "google/protobuf/struct.proto";
service Tasks {
rpc Put (PutRequest) returns (EmptyResponse) {}
rpc Take (TakeRequest) returns (TakeResponse) {}
rpc Finish (FinishRequest) returns (EmptyResponse) {}
}
message Task {
string id = 1;
int64 attempt = 2;
google.protobuf.Struct payload = 3;
}
message PutRequest {
string queue = 1;
int64 seconds_to_execute = 2;
optional int64 delay = 3;
google.protobuf.Struct payload = 4;
}
message TakeRequest {
string queue = 1;
}
message FinishRequest {
string id = 1;
}
message EmptyResponse {}
message TakeResponse {
optional Task task = 1;
}