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

First-class support for leases #1300

Closed
alecthomas opened this issue Apr 18, 2024 · 0 comments
Closed

First-class support for leases #1300

alecthomas opened this issue Apr 18, 2024 · 0 comments
Assignees

Comments

@alecthomas
Copy link
Collaborator

alecthomas commented Apr 18, 2024

Leases are super useful for all kinds of things.

// Define a lease namespace.
var userUpdateLease = ftl.Lease("user", "update")

//ftl:export
func UpdateUser(ctx context.Context, req UpdateUserRequest) error {
  // Obtain a lease on a single user.
  defer userLease.Acquire(ctx, req.UserId).Release()
  // Do a bunch of stuff.
}

The lease key should be a hierarchy perhaps? Should acquiring a lease on user acquire it for all children? Should we even do that?

func Lease(key...string) LeaseHandle

type LeaseHandle struct {}
func (LeaseHandle) Acquire(ctx context.context, key...string) LeaseReservation

type LeaseReservation struct {}
func (LeaseReservation) Release()

Leases would need a table, and a reaper job to cleanup expired leases. We are using a similar concept already for runner and controller reservations which we could probably rewrite using these.

Or should the API be more like:

func Lease(ctx context.Context, key... string) LeaseReservation

//ftl:export
func UpdateUser(ctx context.Context, req UpdateUserRequest) error {
  // Obtain a lease on a single user.
  defer ftl.Lease(ctx, "update", "user", req.UserId).Release()
  // Do a bunch of stuff.
}

Will probably need an additional method on VerbService for renewing the lease.

@github-actions github-actions bot added the triage Issue needs triaging label Apr 18, 2024
@alecthomas alecthomas added the next Work that will be be picked up next label Apr 18, 2024
@github-actions github-actions bot removed the triage Issue needs triaging label Apr 18, 2024
@github-actions github-actions bot removed the next Work that will be be picked up next label Apr 19, 2024
@alecthomas alecthomas assigned matt2e and unassigned wesbillman Apr 20, 2024
@matt2e matt2e assigned alecthomas and unassigned matt2e Apr 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants