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

Update highlights for codehike v1 #221

Merged
merged 1 commit into from
Nov 29, 2024
Merged
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
6 changes: 3 additions & 3 deletions tutorials/tour-of-restate-go/part1/cartobject.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type CartObject struct{}

// <start_add_ticket>
func (CartObject) AddTicket(ctx restate.ObjectContext, ticketId string) (bool, error) {
// withClass highlight-line
// !mark
reservationSuccess, err := restate.Object[bool](ctx, "TicketObject", ticketId, "Reserve").Request(restate.Void{})
if err != nil {
return false, err
Expand All @@ -19,7 +19,7 @@ func (CartObject) AddTicket(ctx restate.ObjectContext, ticketId string) (bool, e

// <start_checkout>
func (CartObject) Checkout(ctx restate.ObjectContext) (bool, error) {
// withClass(1:2) highlight-line
// !mark(1:2)
success, err := restate.Service[bool](ctx, "CheckoutService", "Handle").
Request(CheckoutRequest{UserId: restate.Key(ctx), Tickets: []string{"seat2B"}})
if err != nil {
Expand All @@ -33,7 +33,7 @@ func (CartObject) Checkout(ctx restate.ObjectContext) (bool, error) {

// <start_expire_ticket>
func (CartObject) ExpireTicket(ctx restate.ObjectContext, ticketId string) error {
// withClass highlight-line
// !mark
restate.ObjectSend(ctx, "TicketObject", ticketId, "Unreserve").Send(restate.Void{})

return nil
Expand Down
8 changes: 4 additions & 4 deletions tutorials/tour-of-restate-go/part2/cartobject.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ type CartObject struct{}

// <start_add_ticket>
func (CartObject) AddTicket(ctx restate.ObjectContext, ticketId string) (bool, error) {
// withClass highlight-line
// !mark
reservationSuccess, err := restate.Object[bool](ctx, "TicketObject", ticketId, "Reserve").Request(restate.Void{})
if err != nil {
return false, err
}

if reservationSuccess {
// withClass highlight-line
// !mark
restate.ObjectSend(ctx, "CartObject", restate.Key(ctx), "ExpireTicket").Send(ticketId, restate.WithDelay(15*time.Minute))
}

Expand All @@ -28,7 +28,7 @@ func (CartObject) AddTicket(ctx restate.ObjectContext, ticketId string) (bool, e

// <start_checkout>
func (CartObject) Checkout(ctx restate.ObjectContext) (bool, error) {
// withClass(1:2) highlight-line
// !mark(1:2)
success, err := restate.Service[bool](ctx, "CheckoutService", "Handle").
Request(CheckoutRequest{UserId: restate.Key(ctx), Tickets: []string{"seat2B"}})
if err != nil {
Expand All @@ -42,7 +42,7 @@ func (CartObject) Checkout(ctx restate.ObjectContext) (bool, error) {

// <start_expire_ticket>
func (CartObject) ExpireTicket(ctx restate.ObjectContext, ticketId string) error {
// withClass highlight-line
// !mark
restate.ObjectSend(ctx, "TicketObject", ticketId, "Unreserve").Send(restate.Void{})

return nil
Expand Down
8 changes: 4 additions & 4 deletions tutorials/tour-of-restate-go/part3/cartobject.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ type CartObject struct{}

// <start_add_ticket>
func (CartObject) AddTicket(ctx restate.ObjectContext, ticketId string) (bool, error) {
// withClass highlight-line
// !mark
reservationSuccess, err := restate.Object[bool](ctx, "TicketObject", ticketId, "Reserve").Request(restate.Void{})
if err != nil {
return false, err
}

if reservationSuccess {
// withClass(1:6) highlight-line
// !mark(1:6)
tickets, err := restate.Get[[]string](ctx, "tickets")
if err != nil {
return false, err
Expand All @@ -36,7 +36,7 @@ func (CartObject) AddTicket(ctx restate.ObjectContext, ticketId string) (bool, e

// <start_checkout>
func (CartObject) Checkout(ctx restate.ObjectContext) (bool, error) {
// withClass(1:4) highlight-line
// !mark(1:4)
tickets, err := restate.Get[[]string](ctx, "tickets")
if err != nil || len(tickets) == 0 {
return false, err
Expand All @@ -49,7 +49,7 @@ func (CartObject) Checkout(ctx restate.ObjectContext) (bool, error) {
}

if success {
// withClass highlight-line
// !mark
restate.Clear(ctx, "tickets")
}

Expand Down
2 changes: 1 addition & 1 deletion tutorials/tour-of-restate-go/part4/cartobject.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (CartObject) Checkout(ctx restate.ObjectContext) (bool, error) {
}

if success {
// withClass(1:3) highlight-line
// !mark(1:3)
for _, ticketId := range tickets {
restate.ObjectSend(ctx, "TicketObject", ticketId, "MarkAsSold").Send(restate.Void{})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class CartObject {
// <start_add_ticket>
@Handler
public boolean addTicket(ObjectContext ctx, String ticketId) {
// withClass highlight-line
// !mark
boolean reservationSuccess = TicketObjectClient.fromContext(ctx, ticketId).reserve().await();

return true;
Expand All @@ -34,15 +34,15 @@ public boolean addTicket(ObjectContext ctx, String ticketId) {
// <start_expire_ticket>
@Handler
public void expireTicket(ObjectContext ctx, String ticketId) {
// withClass highlight-line
// !mark
TicketObjectClient.fromContext(ctx, ticketId).send().unreserve();
}
// <end_expire_ticket>

// <start_checkout>
@Handler
public boolean checkout(ObjectContext ctx) {
// withClass(1:3) highlight-line
// !mark(1:3)
boolean checkoutSuccess = CheckoutServiceClient.fromContext(ctx)
.handle(new CheckoutRequest("Mary", Set.of("seat2B")))
.await();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public boolean addTicket(ObjectContext ctx, String ticketId) {
boolean reservationSuccess = TicketObjectClient.fromContext(ctx, ticketId).reserve().await();

if (reservationSuccess) {
// withClass(1:3) highlight-line
// !mark(1:3)
CartObjectClient.fromContext(ctx, ctx.key())
.send(Duration.ofMinutes(15))
.expireTicket(ticketId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class CartObject {

// <start_add_ticket>
// At the top of the class, define the state key: supply a name and (de)serializer
// withClass(1,2) highlight-line
// !mark(1,2)
public static final StateKey<Set<String>> STATE_KEY = StateKey.of("tickets",
JacksonSerdes.of(new TypeReference<>() {}));

Expand All @@ -37,7 +37,7 @@ public boolean addTicket(ObjectContext ctx, String ticketId) {
boolean reservationSuccess = TicketObjectClient.fromContext(ctx, ticketId).reserve().await();

if (reservationSuccess) {
// withClass(1:3) highlight-line
// !mark(1:3)
Set<String> tickets = ctx.get(STATE_KEY).orElseGet(HashSet::new);
tickets.add(ticketId);
ctx.set(STATE_KEY, tickets);
Expand Down Expand Up @@ -68,7 +68,7 @@ public void expireTicket(ObjectContext ctx, String ticketId) {
// <start_checkout>
@Handler
public boolean checkout(ObjectContext ctx) {
// withClass(1:5) highlight-line
// !mark(1:5)
Set<String> tickets = ctx.get(STATE_KEY).orElseGet(HashSet::new);

if (tickets.isEmpty()) {
Expand All @@ -80,7 +80,7 @@ public boolean checkout(ObjectContext ctx) {
.await();

if (checkoutSuccess) {
// withClass highlight-line
// !mark
ctx.clear(STATE_KEY);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public boolean checkout(ObjectContext ctx) {
.await();

if (checkoutSuccess) {
// withClass(1:3) highlight-line
// !mark(1:3)
tickets.forEach(t ->
TicketObjectClient.fromContext(ctx, t).send().markAsSold()
);
Expand Down
6 changes: 3 additions & 3 deletions tutorials/tour-of-restate-python/tour/part1/cart_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# <start_add_ticket>
@cart.handler("addTicket")
async def add_ticket(ctx: ObjectContext, ticket_id: str) -> bool:
# withClass highlight-line
# !mark
reserved = await ctx.object_call(reserve, key=ticket_id, arg=None)

return reserved
Expand All @@ -31,7 +31,7 @@ async def add_ticket(ctx: ObjectContext, ticket_id: str) -> bool:
# <start_checkout>
@cart.handler()
async def checkout(ctx: ObjectContext) -> bool:
# withClass(1:2) highlight-line
# !mark(1:2)
success = await ctx.service_call(handle, arg={'user_id': ctx.key(),
'tickets': ["seat2B"]})

Expand All @@ -42,6 +42,6 @@ async def checkout(ctx: ObjectContext) -> bool:
# <start_expire_ticket>
@cart.handler("expireTicket")
async def expire_ticket(ctx: ObjectContext, ticket_id: str):
# withClass highlight-line
# !mark
ctx.object_send(unreserve, key=ticket_id, arg=None)
# <end_expire_ticket>
4 changes: 2 additions & 2 deletions tutorials/tour-of-restate-python/tour/part2/cart_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async def add_ticket(ctx: ObjectContext, ticket_id: str) -> bool:
reserved = await ctx.object_call(reserve, key=ticket_id, arg=None)

if reserved:
# withClass highlight-line
# !mark
ctx.object_send(expire_ticket, key=ctx.key(), arg=ticket_id, send_delay=timedelta(minutes=15))

return reserved
Expand All @@ -34,7 +34,7 @@ async def add_ticket(ctx: ObjectContext, ticket_id: str) -> bool:
# <start_checkout>
@cart.handler()
async def checkout(ctx: ObjectContext) -> bool:
# withClass(1:2) highlight-line
# !mark(1:2)
success = await ctx.service_call(handle, arg={'user_id': ctx.key(),
'tickets': ["seat2B"]})

Expand Down
8 changes: 4 additions & 4 deletions tutorials/tour-of-restate-python/tour/part3/cart_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async def add_ticket(ctx: ObjectContext, ticket_id: str) -> bool:
reserved = await ctx.object_call(reserve, key=ticket_id, arg=None)

if reserved:
# withClass(1:3) highlight-line
# !mark(1:3)
tickets = await ctx.get("tickets") or []
tickets.append(ticket_id)
ctx.set("tickets", tickets)
Expand All @@ -38,18 +38,18 @@ async def add_ticket(ctx: ObjectContext, ticket_id: str) -> bool:
# <start_checkout>
@cart.handler()
async def checkout(ctx: ObjectContext) -> bool:
# withClass highlight-line
# !mark
tickets = await ctx.get("tickets") or []

# withClass(1:2) highlight-line
# !mark(1:2)
if len(tickets) == 0:
return False

success = await ctx.service_call(handle, arg={'user_id': ctx.key(),
'tickets': tickets})

if success:
# withClass(1:2) highlight-line
# !mark(1:2)
for ticket in tickets:
ctx.object_send(mark_as_sold, key=ticket, arg=None)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export const checkoutService = restate.service({
name: "CheckoutService",
handlers: {
async handle(ctx: restate.Context, request: { userId: string; tickets: string[] }){
console.info("Hello")
return true;
},
}
Expand Down
6 changes: 3 additions & 3 deletions tutorials/tour-of-restate-typescript/src/part1/cart_object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const cartObject = restate.object({
handlers: {
// <start_add_ticket>
async addTicket(ctx: restate.ObjectContext, ticketId: string) {
// withClass highlight-line
// !mark
const reservationSuccess = await ctx.objectClient(TicketObject, ticketId).reserve();

return true;
Expand All @@ -27,7 +27,7 @@ export const cartObject = restate.object({

// <start_checkout>
async checkout(ctx: restate.ObjectContext) {
// withClass(1:2) highlight-line
// !mark(1:2)
const success = await ctx.serviceClient(CheckoutService)
.handle({userId: ctx.key, tickets: ["seat2B"]});

Expand All @@ -37,7 +37,7 @@ export const cartObject = restate.object({

// <start_expire_ticket>
async expireTicket(ctx: restate.ObjectContext, ticketId: string) {
// withClass highlight-line
// !mark
ctx.objectSendClient(TicketObject, ticketId).unreserve();
},
// <end_expire_ticket>
Expand Down
6 changes: 3 additions & 3 deletions tutorials/tour-of-restate-typescript/src/part2/cart_object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const cartObject = restate.object({
const reservationSuccess = await ctx.objectClient(TicketObject, ticketId).reserve();

if (reservationSuccess) {
// withClass(1,2) highlight-line
// !mark(1,2)
ctx.objectSendClient(CartObject, ctx.key, {delay: 15 * 60 * 1000})
.expireTicket(ticketId);
}
Expand All @@ -32,7 +32,7 @@ export const cartObject = restate.object({

// <start_checkout>
async checkout(ctx: restate.ObjectContext) {
// withClass(1:2) highlight-line
// !mark(1:2)
const success = await ctx.serviceClient(CheckoutService)
.handle({userId: ctx.key, tickets: ["seat2B"]});

Expand All @@ -42,7 +42,7 @@ export const cartObject = restate.object({

// <start_expire_ticket>
async expireTicket(ctx: restate.ObjectContext, ticketId: string) {
// withClass highlight-line
// !mark
ctx.objectSendClient(TicketObject, ticketId).unreserve();
}
// <end_expire_ticket>
Expand Down
6 changes: 3 additions & 3 deletions tutorials/tour-of-restate-typescript/src/part3/cart_object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const cartObject = restate.object({
const reservationSuccess = await ctx.objectClient(TicketObject, ticketId).reserve();

if (reservationSuccess) {
// withClass(1:3) highlight-line
// !mark(1:3)
const tickets = (await ctx.get<string[]>("tickets")) ?? [];
tickets.push(ticketId);
ctx.set("tickets", tickets);
Expand All @@ -36,7 +36,7 @@ export const cartObject = restate.object({

// <start_checkout>
async checkout(ctx: restate.ObjectContext) {
// withClass(1:5) highlight-line
// !mark(1:5)
const tickets = (await ctx.get<string[]>("tickets")) ?? [];

if (tickets.length === 0) {
Expand All @@ -47,7 +47,7 @@ export const cartObject = restate.object({
.handle({userId: ctx.key, tickets});

if (success) {
// withClass highlight-line
// !mark
ctx.clear("tickets");
}

Expand Down
Loading