Skip to content

Commit c365ffb

Browse files
[Release] Synchronize for release (#78)
1 parent ae5458f commit c365ffb

File tree

19 files changed

+87
-90
lines changed

19 files changed

+87
-90
lines changed

api/bank/v1/account.proto

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ service AccountMethods {
4141
};
4242
}
4343

44-
// An async task to send a welcome email to the customer.
45-
rpc WelcomeEmailTask(WelcomeEmailTaskRequest)
46-
returns (WelcomeEmailTaskResponse) {
44+
// Sends a welcome email to the customer, scheduled as a task.
45+
rpc WelcomeEmail(WelcomeEmailRequest) returns (WelcomeEmailResponse) {
4746
option (rbt.v1alpha1.method) = {
4847
writer: {},
4948
};
@@ -83,6 +82,6 @@ message WithdrawResponse {
8382
uint64 updated_balance = 1;
8483
}
8584

86-
message WelcomeEmailTaskRequest {}
85+
message WelcomeEmailRequest {}
8786

88-
message WelcomeEmailTaskResponse {}
87+
message WelcomeEmailResponse {}

api/hello_tasks/v1/hello.proto

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@ service HelloMethods {
2121
}
2222

2323
// Adds a "Disappearing soon!" alert to a message.
24-
rpc WarningTask(WarningTaskRequest)
25-
returns (WarningTaskResponse) {
24+
rpc Warning(WarningRequest) returns (WarningResponse) {
2625
option (rbt.v1alpha1.method) = {
2726
writer: {},
2827
};
2928
}
3029

3130
// Removes a message from the history.
32-
rpc EraseTask(EraseTaskRequest) returns (EraseTaskResponse) {
31+
rpc Erase(EraseRequest) returns (EraseResponse) {
3332
option (rbt.v1alpha1.method) = {
3433
writer: {},
3534
};
@@ -63,17 +62,17 @@ message SendResponse {
6362
rbt.v1alpha1.TaskId task_id = 1;
6463
}
6564

66-
message WarningTaskRequest {
65+
message WarningRequest {
6766
string message_id = 1;
6867
}
6968

70-
message WarningTaskResponse {
69+
message WarningResponse {
7170
// The ID of the task scheduled to erase the message.
7271
rbt.v1alpha1.TaskId task_id = 1;
7372
}
7473

75-
message EraseTaskRequest {
74+
message EraseRequest {
7675
string message_id = 1;
7776
}
7877

79-
message EraseTaskResponse {}
78+
message EraseResponse {}

bank/backend/src/account_servicer.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
DepositResponse,
88
OpenRequest,
99
OpenResponse,
10-
WelcomeEmailTaskRequest,
11-
WelcomeEmailTaskResponse,
10+
WelcomeEmailRequest,
11+
WelcomeEmailResponse,
1212
WithdrawRequest,
1313
WithdrawResponse,
1414
)
@@ -32,9 +32,9 @@ async def Open(
3232

3333
# We'd like to send the new customer a welcome email, but that can be
3434
# done asynchronously, so we schedule it as a task.
35-
task = await self.lookup().schedule().WelcomeEmailTask(context)
35+
task_id = await self.ref().schedule().WelcomeEmail(context)
3636

37-
return OpenResponse(welcome_email_task_id=task.task_id)
37+
return OpenResponse(welcome_email_task_id=task_id)
3838

3939
async def Balance(
4040
self,
@@ -67,12 +67,12 @@ async def Withdraw(
6767
state.balance = updated_balance
6868
return WithdrawResponse(updated_balance=updated_balance)
6969

70-
async def WelcomeEmailTask(
70+
async def WelcomeEmail(
7171
self,
7272
context: WriterContext,
7373
state: Account.State,
74-
request: WelcomeEmailTaskRequest,
75-
) -> WelcomeEmailTaskResponse:
74+
request: WelcomeEmailRequest,
75+
) -> WelcomeEmailResponse:
7676
message_body = (
7777
f"Hello {state.customer_name},\n"
7878
"\n"
@@ -85,7 +85,7 @@ async def WelcomeEmailTask(
8585

8686
await send_email(message_body)
8787

88-
return WelcomeEmailTaskResponse()
88+
return WelcomeEmailResponse()
8989

9090

9191
async def send_email(message_body: str):

bank/backend/src/bank_servicer.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ async def SignUp(
2828
new_account_id = str(uuid.uuid4())
2929

3030
# Let's go create the account.
31-
account, _ = await Account.construct(id=new_account_id).Open(
31+
account, _ = await Account.Open(
3232
context,
33+
new_account_id,
3334
customer_name=request.customer_name,
3435
)
3536

@@ -44,8 +45,8 @@ async def Transfer(
4445
state: Bank.State,
4546
request: TransferRequest,
4647
) -> TransferResponse:
47-
from_account = Account.lookup(request.from_account_id)
48-
to_account = Account.lookup(request.to_account_id)
48+
from_account = Account.ref(request.from_account_id)
49+
to_account = Account.ref(request.to_account_id)
4950

5051
await from_account.Withdraw(context, amount=request.amount)
5152
await to_account.Deposit(context, amount=request.amount)

bank/backend/src/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313

1414
async def initialize(context: ExternalContext):
15-
bank = Bank.lookup(SINGLETON_BANK_ID)
15+
bank = Bank.ref(SINGLETON_BANK_ID)
1616

1717
await bank.idempotently().SignUp(
1818
context,

bank/backend/tests/account_servicer_test.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ async def test_basics(self) -> None:
2828
# Create the state machine by calling its constructor. The fact that the
2929
# state machine _has_ a constructor means that this step is required
3030
# before other methods can be called on it.
31-
account, _ = await Account.construct().Open(
32-
context,
33-
customer_name="Alice",
34-
)
31+
account, _ = await Account.Open(context, customer_name="Alice")
3532

3633
# We can now call methods on the state machine. It should have a balance
3734
# of 0.
@@ -89,16 +86,21 @@ async def test_send_welcome_email(self, mock_send_email) -> None:
8986

9087
# When we open an account, we expect the user to receive a welcome
9188
# email.
92-
account, open_response = await Account.construct().Open(
89+
account, open_response = await Account.Open(
9390
context,
9491
customer_name="Alice",
9592
)
9693

94+
welcome_email_task_id = open_response.welcome_email_task_id
95+
9796
# Wait for the email task to run.
98-
await Account.WelcomeEmailTaskFuture(
97+
response = await Account.WelcomeEmailTask.retrieve(
9998
context,
100-
task_id=open_response.welcome_email_task_id,
99+
task_id=welcome_email_task_id,
101100
)
101+
# We are only capturing the response for docs purposes, and
102+
# need to explicitly delete it to avoid linting errors.
103+
del response
102104
# We can expect two attempts to send the email, because Reboot always
103105
# re-runs methods twice in development mode in order to validate that
104106
# calls are idempotent.

bank/backend/tests/bank_servicer_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ async def asyncTearDown(self) -> None:
1919
async def test_signup(self) -> None:
2020
await self.rbt.up(servicers=[BankServicer, AccountServicer])
2121
context = self.rbt.create_external_context(name=f"test-{self.id()}")
22-
bank = Bank.lookup("my-bank")
22+
bank = Bank.ref("my-bank")
2323

2424
# The Bank state machine doesn't have a constructor, so we can simply
2525
# start calling methods on it.
@@ -29,25 +29,25 @@ async def test_signup(self) -> None:
2929
)
3030

3131
# SignUp will have created an Account we can call.
32-
account = Account.lookup(response.account_id)
32+
account = Account.ref(response.account_id)
3333
response = await account.Balance(context)
3434
self.assertEqual(response.balance, 0)
3535

3636
async def test_transfer(self):
3737
await self.rbt.up(servicers=[BankServicer, AccountServicer])
3838
context = self.rbt.create_external_context(name=f"test-{self.id()}")
39-
bank = Bank.lookup("my-bank")
39+
bank = Bank.ref("my-bank")
4040

4141
alice: SignUpResponse = await bank.SignUp(
4242
context,
4343
customer_name="Alice",
4444
)
45-
alice_account = Account.lookup(alice.account_id)
45+
alice_account = Account.ref(alice.account_id)
4646
bob: SignUpResponse = await bank.SignUp(
4747
context,
4848
customer_name="Bob",
4949
)
50-
bob_account = Account.lookup(bob.account_id)
50+
bob_account = Account.ref(bob.account_id)
5151

5252
# Alice deposits some money.
5353
await alice_account.Deposit(context, amount=100)

bank/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ async def run_action(args: argparse.Namespace) -> None:
9797
url=args.application_api_url,
9898
)
9999

100-
bank = Bank.lookup(args.bank_id)
100+
bank = Bank.ref(args.bank_id)
101101
if args.subcommand == "signup":
102102
response = await bank.SignUp(context, customer_name=args.customer_name)
103103
print(
@@ -124,7 +124,7 @@ async def run_action(args: argparse.Namespace) -> None:
124124
print(f"Unexpected error during transfer: {aborted}")
125125
else:
126126
# These commands talk directly to the Account state machine.
127-
account = Account.lookup(args.account_id)
127+
account = Account.ref(args.account_id)
128128
if args.subcommand == "deposit":
129129
response = await account.Deposit(context, amount=args.amount)
130130
print(

hello-constructors/backend/src/main.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212

1313
async def initialize(context: ExternalContext):
1414
# Explicitly create the state machine.
15-
hello, _ = await Hello.construct(
16-
id=EXAMPLE_STATE_MACHINE_ID
17-
).idempotently().Create(
15+
hello, _ = await Hello.idempotently().Create(
1816
context,
17+
EXAMPLE_STATE_MACHINE_ID,
1918
initial_message="Welcome! This message was sent by a constructor.",
2019
)
2120

2221
# Send a message.
2322
await hello.idempotently().Send(
24-
context, message="This message was sent after construction!"
23+
context,
24+
message="This message was sent after construction!",
2525
)
2626

2727
messages_response = await hello.Messages(context)

hello-constructors/backend/tests/hello_servicer_test.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ async def test_hello_constructors(self) -> None:
2121
# Create the state machine by calling its constructor. The fact that the
2222
# state machine _has_ a constructor means that this step is required
2323
# before other methods can be called on it.
24-
hello, _ = await Hello.construct().Create(
25-
context,
26-
initial_message="first message",
27-
)
24+
hello, _ = await Hello.Create(context, initial_message="first message")
2825

2926
# Send another message.
3027
await hello.Send(context, message="second message")

0 commit comments

Comments
 (0)