Skip to content

Commit

Permalink
Added remarket env variables
Browse files Browse the repository at this point in the history
  • Loading branch information
vince0656 committed Aug 19, 2019
1 parent e0f52c1 commit a6a1c50
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 59 deletions.
3 changes: 3 additions & 0 deletions app/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,3 +696,6 @@
'name': 'Index View',
}]
SILKY_MAX_RECORDED_REQUESTS_CHECK_PERCENT = env.int('SILKY_MAX_RECORDED_REQUESTS_CHECK_PERCENT', default=10)

RE_MARKET_LIMIT = env.int('RE_MARKET_LIMIT', default=2)
MINUTES_BETWEEN_RE_MARKETING = env.int('MINUTES_BETWEEN_RE_MARKETING', default=60)
100 changes: 51 additions & 49 deletions app/dashboard/tests/test_dashboard_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,62 +156,64 @@ def test_can_successfully_re_market_a_bounty():
result = re_market_bounty(bounty, False)

assert result['success'] is True
assert result['msg'] == "The issue will appear at the top of the issue explorer. You will be able to remarket this bounty one more time if a contributor does not pick this up."
assert result['msg'] == f"The issue will appear at the top of the issue explorer. You will be able to remarket this bounty {settings.RE_MARKET_LIMIT - 1} more time if a contributor does not pick this up."
assert bounty.remarketed_count == 1
assert bounty.last_remarketed > (timezone.now() - timezone.timedelta(minutes=1))

@staticmethod
def test_can_successfully_re_market_a_bounty_twice():
bounty = Bounty.objects.create(
title='CanRemarketTrueTest',
idx_status=0,
is_open=True,
web3_created=datetime(2008, 10, 31, tzinfo=UTC),
expires_date=datetime(2008, 11, 30, tzinfo=UTC),
last_remarketed=datetime(2008, 10, 31, tzinfo=UTC),
github_url='https://github.com/gitcoinco/web/issues/12345678',
raw_data={}
)

result = re_market_bounty(bounty, False)
assert result['success'] is True
assert result['msg'] == "The issue will appear at the top of the issue explorer. You will be able to remarket this bounty one more time if a contributor does not pick this up."
assert bounty.remarketed_count == 1

bounty.last_remarketed = timezone.now() - timezone.timedelta(hours=2)

result = re_market_bounty(bounty, False)
assert result['success'] is True
assert result['msg'] == "The issue will appear at the top of the issue explorer. Please note this is the last time the issue is able to be remarketed."
assert bounty.remarketed_count == 2
if settings.RE_MARKET_LIMIT == 2:
bounty = Bounty.objects.create(
title='CanRemarketTrueTest',
idx_status=0,
is_open=True,
web3_created=datetime(2008, 10, 31, tzinfo=UTC),
expires_date=datetime(2008, 11, 30, tzinfo=UTC),
last_remarketed=datetime(2008, 10, 31, tzinfo=UTC),
github_url='https://github.com/gitcoinco/web/issues/12345678',
raw_data={}
)

result = re_market_bounty(bounty, False)
assert result['success'] is True
assert result['msg'] == "The issue will appear at the top of the issue explorer. You will be able to remarket this bounty 1 more time if a contributor does not pick this up."
assert bounty.remarketed_count == 1

bounty.last_remarketed = timezone.now() - timezone.timedelta(hours=2)

result = re_market_bounty(bounty, False)
assert result['success'] is True
assert result['msg'] == "The issue will appear at the top of the issue explorer. Please note this is the last time the issue is able to be remarketed."
assert bounty.remarketed_count == 2

@staticmethod
def test_re_market_fails_after_reaching_re_market_limit():
bounty = Bounty.objects.create(
title='CanRemarketFalseTest',
idx_status=0,
is_open=True,
web3_created=datetime(2008, 10, 31, tzinfo=UTC),
expires_date=datetime(2008, 11, 30, tzinfo=UTC),
last_remarketed=datetime(2008, 10, 31, tzinfo=UTC),
github_url='https://github.com/gitcoinco/web/issues/12345678',
raw_data={}
)

assert bounty.remarketed_count == 0
result = re_market_bounty(bounty, False)
assert result['success'] is True
assert bounty.remarketed_count == 1

bounty.last_remarketed = timezone.now() - timezone.timedelta(hours=2)

result = re_market_bounty(bounty, False)
assert result['success'] is True
assert bounty.remarketed_count == 2

result = re_market_bounty(bounty, False)
assert result['success'] is False
assert result['msg'] == "The issue was not remarketed due to reaching the remarket limit (2)."
if settings.RE_MARKET_LIMIT == 2:
bounty = Bounty.objects.create(
title='CanRemarketFalseTest',
idx_status=0,
is_open=True,
web3_created=datetime(2008, 10, 31, tzinfo=UTC),
expires_date=datetime(2008, 11, 30, tzinfo=UTC),
last_remarketed=datetime(2008, 10, 31, tzinfo=UTC),
github_url='https://github.com/gitcoinco/web/issues/12345678',
raw_data={}
)

assert bounty.remarketed_count == 0
result = re_market_bounty(bounty, False)
assert result['success'] is True
assert bounty.remarketed_count == 1

bounty.last_remarketed = timezone.now() - timezone.timedelta(hours=2)

result = re_market_bounty(bounty, False)
assert result['success'] is True
assert bounty.remarketed_count == 2

result = re_market_bounty(bounty, False)
assert result['success'] is False
assert result['msg'] == "The issue was not remarketed due to reaching the remarket limit (2)."

@staticmethod
def test_re_market_fails_after_re_marketing_in_quick_succession():
Expand Down Expand Up @@ -256,7 +258,7 @@ def test_apply_new_bounty_deadline_is_successful_with_re_market():
re_market_result = apply_new_bounty_deadline(bounty, deadline, False)
assert bounty.remarketed_count == 1
assert re_market_result['success'] is True
assert re_market_result['msg'] == "You've extended expiration of this issue. The issue will appear at the top of the issue explorer. You will be able to remarket this bounty one more time if a contributor does not pick this up."
assert re_market_result['msg'] == "You've extended expiration of this issue. The issue will appear at the top of the issue explorer. You will be able to remarket this bounty 1 more time if a contributor does not pick this up."

deadline_as_date_time = timezone.make_aware(
timezone.datetime.fromtimestamp(deadline),
Expand Down
20 changes: 10 additions & 10 deletions app/dashboard/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -832,10 +832,10 @@ def get_nonce(network, address):

def re_market_bounty(bounty, auto_save = True):
remarketed_count = bounty.remarketed_count
if remarketed_count < 2:
if remarketed_count < settings.RE_MARKET_LIMIT:
now = timezone.now()
one_hour_after_remarketing = bounty.last_remarketed + timezone.timedelta(hours=1) if bounty.last_remarketed else now
if now >= one_hour_after_remarketing:
minimum_wait_after_remarketing = bounty.last_remarketed + timezone.timedelta(minutes=settings.MINUTES_BETWEEN_RE_MARKETING) if bounty.last_remarketed else now
if now >= minimum_wait_after_remarketing:
bounty.remarketed_count = remarketed_count + 1
bounty.last_remarketed = now

Expand All @@ -844,19 +844,19 @@ def re_market_bounty(bounty, auto_save = True):

maybe_market_to_slack(bounty, 'issue_remarketed')

result_msg = "The issue will appear at the top of the issue explorer. "
further_permitted_remarket_count = 2 - bounty.remarketed_count
if further_permitted_remarket_count == 1:
result_msg += "You will be able to remarket this bounty one more time if a contributor does not pick this up."
result_msg = 'The issue will appear at the top of the issue explorer. '
further_permitted_remarket_count = settings.RE_MARKET_LIMIT - bounty.remarketed_count
if further_permitted_remarket_count >= 1:
result_msg += f'You will be able to remarket this bounty {further_permitted_remarket_count} more time if a contributor does not pick this up.'
elif further_permitted_remarket_count == 0:
result_msg += "Please note this is the last time the issue is able to be remarketed."
result_msg += 'Please note this is the last time the issue is able to be remarketed.'

return {
"success": True,
"msg": result_msg
}
else:
time_delta_wait_time = one_hour_after_remarketing - now
time_delta_wait_time = minimum_wait_after_remarketing - now
minutes_to_wait = round(time_delta_wait_time.total_seconds() / 60)
return {
"success": False,
Expand All @@ -865,7 +865,7 @@ def re_market_bounty(bounty, auto_save = True):
else:
return {
"success": False,
"msg": "The issue was not remarketed due to reaching the remarket limit (2)."
"msg": f'The issue was not remarketed due to reaching the remarket limit ({settings.RE_MARKET_LIMIT}).'
}


Expand Down

0 comments on commit a6a1c50

Please sign in to comment.