Skip to content

Commit

Permalink
Merge pull request #35 from Azure-Samples/virtual-worker-restart
Browse files Browse the repository at this point in the history
Virtual worker restart
  • Loading branch information
chzbrgr71 committed Jul 5, 2023
2 parents 1755783 + 56ee758 commit e9bd6e3
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 39 deletions.
2 changes: 1 addition & 1 deletion src/ai-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ INFO: Application startup complete.
INFO: Uvicorn running on http://127.0.0.1:5001 (Press CTRL+C to quit)
```

Using the [`test-ai-service.http`](../../test-ai-service.http) file in the root of the repo, you can test the API. However, you will need to use VS Code and have the [REST Client](https://marketplace.visualstudio.com/items?itemName=humao.rest-client) extension installed.
Using the [`test-ai-service.http`](./test-ai-service.http) file in the root of the repo, you can test the API. However, you will need to use VS Code and have the [REST Client](https://marketplace.visualstudio.com/items?itemName=humao.rest-client) extension installed.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/makeline-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Please check https://pkg.go.dev/github.com/gin-gonic/gin#readme-don-t-trust-all-
[GIN-debug] Listening and serving HTTP on :3001
```

Using the [`test-makeline-service.http`](../../test-makeline-service.http) file in the root of the repo, you can test the API. However, you will need to use VS Code and have the [REST Client](https://marketplace.visualstudio.com/items?itemName=humao.rest-client) extension installed.
Using the [`test-makeline-service.http`](./test-makeline-service.http) file in the root of the repo, you can test the API. However, you will need to use VS Code and have the [REST Client](https://marketplace.visualstudio.com/items?itemName=humao.rest-client) extension installed.

To view the orders in MongoDB, open a terminal and run the following command:

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/order-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ When the app is running, you should see output similar to the following:
[1687920999327] INFO (108877 on yubuntu): Server listening at http://127.0.0.1:3000
```

Using the [`test-order-service.http`](../../test-order-service.http) file in the root of the repo, you can test the API. However, you will need to use VS Code and have the [REST Client](https://marketplace.visualstudio.com/items?itemName=humao.rest-client) extension installed.
Using the [`test-order-service.http`](./test-order-service.http) file in the root of the repo, you can test the API. However, you will need to use VS Code and have the [REST Client](https://marketplace.visualstudio.com/items?itemName=humao.rest-client) extension installed.

To view the order messages in RabbitMQ, open a browser and navigate to [http://localhost:15672](http://localhost:15672). Log in with the username and password you provided in the environment variables above. Then click on the **Queues** tab and click on your **orders** queue. After you've submitted a few orders, you should see the messages in the queue.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/product-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ Listening on http://0.0.0.0:3002
[2023-06-28T02:44:47Z INFO actix_server::server] Actix runtime found; starting in Actix runtime
```

Using the [`test-product-service.http`](../../test-product-service.http) file in the root of the repo, you can test the API. However, you will need to use VS Code and have the [REST Client](https://marketplace.visualstudio.com/items?itemName=humao.rest-client) extension installed.
Using the [`test-product-service.http`](./test-product-service.http) file in the root of the repo, you can test the API. However, you will need to use VS Code and have the [REST Client](https://marketplace.visualstudio.com/items?itemName=humao.rest-client) extension installed.
File renamed without changes.
84 changes: 49 additions & 35 deletions src/virtual-worker/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,43 +46,57 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

match response {
Ok(res) => {
// parse the text into json
let json = res.text()?;

let orders: Vec<Order> = serde_json::from_str(&json)?;

// loop through the orders
for mut order in orders {
// update order status
order.status = OrderStatus::Processing as u32;

// send the order to the order service
let serialized_order = serde_json::to_string(&order)?;
let client = reqwest::blocking::Client::new();

let response = client
.put(format!("{}/order", order_service_url))
.header("Content-Type", "application/json")
.body(serialized_order.clone())
.send();

match response {
Ok(_res) => {
// track the time it takes to generate an order
let elapsed_time = start_time.elapsed();

// print the order details
println!(
"Order {} processed at {:.2?} with status of {}. {}",
order.order_id, elapsed_time, order.status, serialized_order
);
}
Err(err) => {
println!("Error completing the order: {}", err);
let json = res.text().unwrap();

if json == "null" {
println!("No orders to process");
} else {
println!("Processing orders");

let orders: Vec<Order> = serde_json::from_str(&json).unwrap();

if orders.len() == 0 {
println!("No orders to process");
} else {
println!("Processing {} orders", orders.len());

// loop through the orders
for mut order in orders {
// update order status
order.status = OrderStatus::Processing as u32;

// send the order to the order service
let serialized_order = serde_json::to_string(&order)?;
let client = reqwest::blocking::Client::new();

let response = client
.put(format!("{}/order", order_service_url))
.header("Content-Type", "application/json")
.body(serialized_order.clone())
.send();

match response {
Ok(_res) => {
// track the time it takes to generate an order
let elapsed_time = start_time.elapsed();

// print the order details
println!(
"Order {} processed at {:.2?} with status of {}. {}",
order.order_id,
elapsed_time,
order.status,
serialized_order
);
}
Err(err) => {
println!("Error completing the order: {}", err);
}
}

thread::sleep(sleep_duration);
}
}

thread::sleep(sleep_duration);
}
}
Err(e) => {
Expand Down

0 comments on commit e9bd6e3

Please sign in to comment.