Skip to content

Commit

Permalink
worker: include orgs in reconciler runs (PROJQUAY-8431) (quay#3560)
Browse files Browse the repository at this point in the history
Adds an include_orgs param to the active users query used by the reconciler and sets it to true for reconciler runs

Reconciler is not including orgs as a candidate for creating corresponding RH entitlements. As a result it misses users with stripe billing that are considered orgs.
  • Loading branch information
Marcusk19 authored Jan 10, 2025
1 parent 70a0ede commit 8d835a9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
5 changes: 4 additions & 1 deletion data/model/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -1231,9 +1231,12 @@ def get_public_repo_count(username):
)


def get_active_users(disabled=True, deleted=False):
def get_active_users(disabled=True, deleted=False, include_orgs=False):
query = User.select().where(User.organization == False, User.robot == False)

if include_orgs:
query = User.select().where(User.robot == False)

if not disabled:
query = query.where(User.enabled == True)
else:
Expand Down
2 changes: 1 addition & 1 deletion workers/reconciliationworker.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def _perform_reconciliation(self, user_api, marketplace_api):
"""
logger.info("Reconciliation worker looking to create new subscriptions...")

users = model.user.get_active_users()
users = model.user.get_active_users(include_orgs=True)

stripe_users = [user for user in users if user.stripe_id is not None]

Expand Down
12 changes: 12 additions & 0 deletions workers/test/test_reconciliationworker.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ def test_skip_free_user(initialized_db):
mock.assert_not_called()


def test_reconcile_org_user(initialized_db):
user = model.user.get_user("devtable")

org_user = model.organization.create_organization("org_user", "[email protected]", user)
org_user.stripe_id = "cus_" + "".join(random.choices(string.ascii_lowercase, k=14))
org_user.save()
with patch.object(marketplace_users, "lookup_customer_id") as mock:
worker._perform_reconciliation(marketplace_users, marketplace_subscriptions)

mock.assert_called_with(org_user.email)


def test_exception_handling(initialized_db):
with patch("data.billing.FakeStripe.Customer.retrieve") as mock:
mock.side_effect = stripe.error.InvalidRequestException
Expand Down

0 comments on commit 8d835a9

Please sign in to comment.