Skip to content
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
4 changes: 3 additions & 1 deletion internal/api/handler_marketplace_poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ package api
// pending because AWS gave no status when it was created (issue #1494). It
// records the listing as active with its AWS CreateDate while it is for sale,
// and its terminal state with the realized proceeds and the AWS fee once it
// closes (all sold) or is canceled after a partial sale.
// closes (all sold) or is canceled after a partial sale. A listing the RI was
// relisted from is still read and settled, from the per-listing settlement
// rows the store keeps (issue #1494).
//
// It runs from the finalize_revocations scheduled task (see
// internal/server/handler_marketplace_poll.go), so only where that task is
Expand Down
24 changes: 16 additions & 8 deletions internal/config/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,10 +514,12 @@ type StoreInterface interface {
// they are cleared because AWS created nothing reusable.
ReleaseMarketplaceListingClaim(ctx context.Context, purchaseID, clientToken, priorState string, keepAttempt bool) error

// ListMarketplaceListingsToPoll returns the AWS rows whose listing the
// marketplace status poller reads (issue #27): active listings, listings
// recorded as pending with no list attempt in flight (issue #1494), and
// closed/canceled ones it has seen whose proceeds are not recorded yet.
// ListMarketplaceListingsToPoll returns the AWS listings the marketplace
// status poller reads (issue #27): active listings, listings recorded as
// pending with no list attempt in flight (issue #1494), and
// closed/canceled ones it has seen whose proceeds are not recorded yet,
// both the RI's current listing and the listings it was relisted from
// (issue #1494).
ListMarketplaceListingsToPoll(ctx context.Context) ([]PurchaseHistoryRecord, error)

// RecordMarketplaceListingActive records a listing AWS reports active:
Expand All @@ -529,12 +531,18 @@ type StoreInterface interface {
RecordMarketplaceListingActive(ctx context.Context, purchaseID, listingID string, listedAt time.Time) (bool, error)

// SettleMarketplaceListing records a listing that closed or was canceled
// on AWS, with its proceeds and AWS fee when known. It applies once per
// listing, only while the row still holds it and is active, pending with
// no list attempt in flight, or already in the same terminal state.
// Reports whether the row was written.
// on AWS, with its proceeds and AWS fee when known, in the listing's own
// settlement row and, while the RI still holds the listing, on its
// purchase_history row (issue #1494). It applies once per listing, only
// while the listing is active, pending with no list attempt in flight, or
// already in the same terminal state. Reports whether a row was written.
SettleMarketplaceListing(ctx context.Context, settlement MarketplaceListingSettlement) (bool, error)

// GetMarketplaceListingProceedsTotals sums each RI's marketplace proceeds
// and fees over all of its listings (issue #1494), one total per purchase
// and currency. RIs with no recorded listing are left out.
GetMarketplaceListingProceedsTotals(ctx context.Context, purchaseIDs []string) ([]MarketplaceListingProceedsTotal, error)

// ClaimRIExchangeIdempotencyKey atomically claims key for an RI exchange
// submit, so a client that retries a timed-out execute request cannot
// commit the same exchange twice (issue #1642). key is a fingerprint of
Expand Down
9 changes: 8 additions & 1 deletion internal/config/store_postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -2429,6 +2429,9 @@ func (s *PostgresStore) UpdatePurchaseHistoryListing(ctx context.Context, purcha
// Writing a new listing id (a relist) drops the previous listing's
// listed_at and settlement in the same statement (issue #27), so the new
// listing can be settled even if it ends before the poller sees it active.
// The previous listing itself is kept in marketplace_listing_settlements
// by trigger purchase_history_keep_superseded_listing (migration 000153,
// issue #1494), where the poller still settles it.
query := `
UPDATE purchase_history
SET listing_id = $1, listing_state = $2,
Expand Down Expand Up @@ -2473,7 +2476,11 @@ func (s *PostgresStore) StampOfferingClass(ctx context.Context, purchaseID, offe
// priceSchedule in the same statement unless an earlier attempt already stored a
// token, and returns the row's values as of the claim (issue #525): the handler
// must not trust a row read before the claim. It returns (nil, nil) when the row
// could not be claimed (active, pending without a token, or absent).
// could not be claimed (active, pending without a token, or absent). The
// claimed row keeps the previous listing id but no longer records that
// listing's state, so trigger purchase_history_keep_superseded_listing copies
// the previous listing into marketplace_listing_settlements when the token is
// first stored (migration 000153, issue #1494).
//
// Rows saved before migration 000108 can share a purchase_id (#267). The claim
// then works on the earliest row (created_at, then id), the one
Expand Down
5 changes: 3 additions & 2 deletions internal/config/store_postgres_marketplace_attempt.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ func (s *PostgresStore) GetMarketplaceListingAttempt(ctx context.Context, purcha
// caller just canceled). state must be an ended state (canceled or closed) or
// empty, which clears a stuck pending row that has no listing; an empty
// listingID clears the listing id too. A new listing id drops the previous
// listing's listed_at and settlement (issue #27). It reports whether the row
// was written.
// listing's listed_at and settlement (issue #27); the previous listing is
// kept in marketplace_listing_settlements (migration 000153, issue #1494). It
// reports whether the row was written.
func (s *PostgresStore) ResolveMarketplaceListingAttempt(ctx context.Context, purchaseID string, seen MarketplaceListingAttempt, listingID, state string) (bool, error) {
if state != "" && !isEndedListingState(state) {
return false, fmt.Errorf("cannot resolve marketplace listing %s for purchase %s to live state %q", listingID, purchaseID, state)
Expand Down
Loading
Loading