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

feature/adding_messages_to_queue #27

Open
wants to merge 1 commit into
base: main
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
29 changes: 25 additions & 4 deletions app/resources/queues/queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@
"lifecycleState": "ACTIVE",
"lifecycleDetails": None,
"messagesEndpoint": "http://localhost:12000",
# this is not returned by list method
"retentionInSeconds": 86400,
"visibilityInSeconds": 30,
"timeoutInSeconds": 30,
"deadLetterQueueDeliveryCount": 0,
"customEncryptionKeyId": None,
"channelConsumptionLimit": 100,
# tags
"capabilities": [],
"freeformTags": {},
"definedTags": {},
Expand All @@ -33,9 +41,20 @@
)


def list_queues(compartment_id):
def list_queues(compartment_id, lifecycle_state=None):
global queues
return [queue for queue in queues if queue["compartmentId"] == compartment_id]
returned_queues = []

for queue in queues:
if queue["compartmentId"] != compartment_id:
continue

Check warning on line 50 in app/resources/queues/queues.py

View check run for this annotation

Codecov / codecov/patch

app/resources/queues/queues.py#L50

Added line #L50 was not covered by tests

if lifecycle_state and queue["lifecycleState"] != lifecycle_state:
continue

Check warning on line 53 in app/resources/queues/queues.py

View check run for this annotation

Codecov / codecov/patch

app/resources/queues/queues.py#L53

Added line #L53 was not covered by tests

returned_queues.append(queue)

return returned_queues


def get_queue_by_id(queue_id):
Expand All @@ -50,8 +69,10 @@
global queues
for queue in queues:
if queue["id"] == queue_id:

queues.remove(queue)
queue["lifecycleState"] = "DELETED"
queue["timeUpdated"] = datetime.datetime.utcnow().strftime(
"%Y-%m-%dT%H:%M:%S.%f+00:00"
)

return True, None

Expand Down
68 changes: 63 additions & 5 deletions app/routes/queues/queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

@queues.route("/<date>/queues", methods=["POST"])
def post_queues(date: str):

data = json.loads(request.data)
add_queue(data)

Expand All @@ -35,9 +34,13 @@

@queues.route("/<date>/queues", methods=["GET"])
def get_list_queues(date: str):

response = {
"items": list_queues(compartment_id=request.args["compartmentId"]),
"items": list_queues(
compartment_id=request.args["compartmentId"],
lifecycle_state=request.args["lifecycleState"]
if "lifecycleState" in request.args
else None,
),
}

return Response(
Expand All @@ -54,7 +57,6 @@

@queues.route("/<date>/queues/<queue_id>", methods=["GET"])
def get_queues(date: str, queue_id: str):

response = get_queue_by_id(queue_id)

return Response(
Expand All @@ -71,7 +73,6 @@

@queues.route("/<date>/queues/<queue_id>", methods=["DELETE"])
def delete_queues(date: str, queue_id: str):

success, err = delete_queue(queue_id)

if not success:
Expand All @@ -95,3 +96,60 @@
else ""
},
)


@queues.route("/<date>/queues/<queue_id>/messages", methods=["POST"])
def post_messages(date: str, queue_id: str):
data = json.loads(request.data)
print(data)

Check warning on line 104 in app/routes/queues/queues.py

View check run for this annotation

Codecov / codecov/patch

app/routes/queues/queues.py#L103-L104

Added lines #L103 - L104 were not covered by tests

return Response(

Check warning on line 106 in app/routes/queues/queues.py

View check run for this annotation

Codecov / codecov/patch

app/routes/queues/queues.py#L106

Added line #L106 was not covered by tests
status=200,
content_type="application/json",
headers={
"opc-request-id": request.headers["Opc-Request-Id"]
if "Opc-Request-Id" in request.headers
else ""
},
response=json.dumps(
{
"messages": [
{
"id": 144115188077707275,
"expireAfter": "2023-09-28T12:51:33.522Z",
}
]
}
),
)


@queues.route("/<date>/queues/<queue_id>/messages", methods=["GET"])
def get_messages(date: str, queue_id: str):
# data = json.loads(request.data)
# print(data)

return Response(

Check warning on line 132 in app/routes/queues/queues.py

View check run for this annotation

Codecov / codecov/patch

app/routes/queues/queues.py#L132

Added line #L132 was not covered by tests
status=200,
content_type="application/json",
headers={
"opc-request-id": request.headers["Opc-Request-Id"]
if "Opc-Request-Id" in request.headers
else ""
},
response=json.dumps(
{
"messages": [
{
"content": '{"name": "zéca" }',
"deliveryCount": 2,
"expireAfter": "2023-09-27T19:49:45.430000+00:00",
"id": 144115188077669364,
"metadata": None,
"receipt": "AVrHE2SlpkubAJiEgstJHDJr925mr4S-Fbw-n5yJTxAON-E7LEQOt1f6XHstKVIPv0h6yVnuPxxfDF3wq5jLBx_a5pkr0Uf9wAe15UzgbTvLGaSVzBHTmJtQTuYIunfxL8EaDzZzpVoHq4wzSPFQhY4y2NQ8UCi-gC4I4eerj8A0Ju2TIHM8w7GQpls-7aPSMfeC2WxZ44sDf72vDFveadSrm510W-NdfERWMjZohBvugdpZlfq0kxlOHhVm1zpznJslp1vUjpoi7NX4V_p5YbIV4-ZcUpypDhRAVIKYCCxhRhSJzcxIjwnsuHwfE-OXvv4nXXMkW3FPwo3DNhw0jIqnb7j9bmoQQ91khAU",
"visibleAfter": "2023-09-27T15:05:42.576000+00:00",
}
]
}
),
)
97 changes: 86 additions & 11 deletions reverse_engineering/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,95 @@ import { Region, SimpleAuthenticationDetailsProvider, OciSdkDefaultRetryConfigur
const privateKey = await fs.readFile(ociKeyFile);
const provider = new SimpleAuthenticationDetailsProvider(tenancy, user, fingerprint, privateKey.toString(), passphare, Region.SA_SAOPAULO_1);

// Create a service client
const clientAdmin = new QueueAdminClient({ authenticationDetailsProvider: provider });
clientAdmin.endpoint = 'http://localhost:12000';
const queueTest = await clientAdmin.createQueue({
createQueueDetails: {
compartmentId: compartmentId,
displayName: 'queue-test'
}
});
console.log('queueTest', queueTest);
// // Create a service client
// const clientAdmin = new QueueAdminClient({ authenticationDetailsProvider: provider });
// // clientAdmin.endpoint = 'http://localhost:12000';
// // const queueTest = await clientAdmin.createQueue({
// // createQueueDetails: {
// // compartmentId: compartmentId,
// // displayName: 'queue-test',
// // visibilityInSeconds: 60,
// // retentionInSeconds: 3600
// // }
// // });

// // console.log('queueTest', queueTest);


// queue.queue.retentionInSeconds;

// const response = await clientAdmin.listQueues({ compartmentId: compartmentId, lifecycleState: 'ACTIVE' });

// console.log('items', response.queueCollection.items);

const client = new QueueClient({ authenticationDetailsProvider: provider }, {
retryConfiguration: NoRetryConfigurationDetails
retryConfiguration: OciSdkDefaultRetryConfiguration
});
client.endpoint = 'http://localhost:12000';

const queueId = 'ocid1.queue.oc1.sa-saopaulo-1.amaaaaaaepyaiqaa5hevtxw4qwcn74lidgaj4ogc56qo43zosyhn2pgy5vea';
// const putMessage = await client.putMessages({
// queueId: queueId,
// putMessagesDetails: {
// messages: [{ content: 'meu_conteudo' }]
// }
// });
// console.log('putMessage', putMessage);
// // putMessage {
// // putMessages: { messages: [ [Object] ] },
// // opcRequestId: '90748C906DCB-11EE-B12D-557D64907/AE6F70BBE4830841876979DB016F3253/EEC06A140AFA655D62D6BE0C796088CD'
// // }

// console.log('putMessage', putMessage.putMessages.messages); // putMessage [ { id: 54043195530795490, expireAfter: '2023-10-19T15:32:36.698Z' } ] 24 hours after creation

// const stats = await client.getStats({ queueId: queueId });
// console.log('stats', stats);
// // stats {
// // queueStats: {
// // queue: { visibleMessages: 3, inFlightMessages: 0, sizeInBytes: 36 },
// // dlq: { visibleMessages: 0, inFlightMessages: 0, sizeInBytes: 0 }
// // },
// // opcRequestId: 'F1E417706DCB-11EE-840D-5D57805A3/F152EFE702D4B7A1C4B7FAB22B56308F/AC43218A9CC1F04E2C7588D1F834F893'
// // }

// const messages = await client.getMessages({ queueId: queueId, limit: 1 });
// console.log('messages', messages);
// // messages {
// // getMessages: { messages: [ [Object] ] },
// // opcRequestId: '22DC8F606DCC-11EE-889D-612D6B1E9/F79D182D1B5EF39F17166EF88A2809D0/4F7F5F3A8985ABB7C57FE35351B9870F'
// // }
// console.log('messages', messages.getMessages.messages);
// // messages [
// // {
// // id: 54043195530795460,
// // content: 'meu_conteudo',
// // receipt: 'AbJWn7bA-fgZAPD7CgUyKb7o9LBakWydf86uas63dsvW7qaiF1HQWgqa3v_e_ZfWEkfZVQQOpkPtTT1g4AleYcdyGbQfQameWwFs-n--83Bqz4WfSJN30IZg3SY-oHgFUCy0xBSufoaH7_bdtdZRcCCicH9nCC78g5JZoCHpGUboM0kv-QwjyD-RNqMiEd5yMtigAOC6lJItJFUjrCXd_CRmDVT28AQKnzlv3i6tJ3KPvGC9tGElr2PWh6RZRJWmMxiW6Diq-IADh61cCiZj-_2s1N2H7dykqCRatpZWKvEBAurLWu_TYHnge_3kPp3x43swR8E6BLBooHMxSItvPydtzqxwuCWLwmQS0l0',
// // deliveryCount: 1,
// // visibleAfter: '2023-10-18T15:37:38.283Z', // default value 30 seconds
// // expireAfter: '2023-10-19T15:32:14.587Z',
// // metadata: undefined
// // }
// // ]

// const deleted = await client.deleteMessage({ queueId: queueId, messageReceipt: 'AbJWn7bA-fgZAPD7CgUyKb7o9LBakWydf86uas63dsvW7qaiF1HQWgqa3v_e_ZfWEkfZVQQOpkPtTT1g4AleYcdyGbQfQameWwFs-n--83Bqz4WfSJN30IZg3SY-oHgFUCy0xBSufoaH7_bdtdZRcCCicH9nCC78g5JZoCHpGUboM0kv-QwjyD-RNqMiEd5yMtigAOC6lJItJFUjrCXd_CRmDVT28AQKnzlv3i6tJ3KPvGC9tGElr2PWh6RZRJWmMxiW6Diq-IADh61cCiZj-_2s1N2H7dykqCRatpZWKvEBAurLWu_TYHnge_3kPp3x43swR8E6BLBooHMxSItvPydtzqxwuCWLwmQS0l0' });
// console.log('deleted', deleted);
// // deleted {
// // opcRequestId: '94F39A206DCD-11EE-9C72-D5C2AC67B/2B20F9DC559CF810B7856EE92355701E/ECB0BBF85E62F4B5AE7ED544D2072B3F'
// // }
// // 409 if didn't find receipt

// const updated = await client.updateMessage({
// queueId: queueId,
// messageReceipt: 'AdcxGxAGNo9LALFq14ceYVRJi1VoTSyRTiQLfFpFNtNBmp4G4ZodEGHJ_EXKboWCcwJw7rDlbrH4SxFUMio0N070Q_Z4jiZB3iBwBmerKIIfkMKnNIKSz8QTZpJHqoRa1drhvBWIAb7HjvBPZZti-3EvT87wIjuX0KlxizmwhPnIDXXIVXd9j-gwYOrZwcWWP4dyUfdQPgsuD3rgFJW_2wBwwQc6rLOdpqVBNIUYi4-wVagxlAza4VF0pG808QT26Xj-g5qt6DM2p1DNGBA1gjC2Ia8Erz_fr1fBpadHuUd7MxftDweNSkRj_M515BDFauJjouolWjIfQL3vkXw2CvNxZbqt3Uf5F-QZQZk',
// updateMessageDetails: {
// visibilityInSeconds: 666
// }
// });
// console.log('updated', updated);
// // updated {
// // updatedMessage: { id: 54043195530795490, visibleAfter: '2023-10-18T16:00:54.874Z' },
// // opcRequestId: 'F7B6CE206DCD-11EE-A009-CF772D1F5/00C0DB1ECA86E68C0225079CDAB37DFA/519984818FD916B30C0C2C623A992059'
// // }

} catch (error) {
console.error(error);
Expand Down
2 changes: 1 addition & 1 deletion tests/test_queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_bucket_route(self):
self.assertEqual(r.status, 200)

# list queues
r = cli.list_queues(compartment_id="compartment_id")
r = cli.list_queues(compartment_id="compartment_id", lifecycle_state="ACTIVE")
self.assertEqual(r.status, 200)
self.assertEqual(len(r.data.items), 1)
self.assertEqual(r.data.items[0].display_name, "queue_test")
Expand Down
Loading