# Badge grant fails if any throw exception

**URL:** <https://meta.discourse.org/t/badge-grant-fails-if-any-throw-exception/26935>\
**Category:** Bug\
**Created:** [2015年三月29日 01:37 UTC](https://meta.discourse.org/t/badge-grant-fails-if-any-throw-exception/26935 "2015-03-29T01:37:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)\
**Post date:** [2015年三月29日 01:37 UTC](https://meta.discourse.org/t/badge-grant-fails-if-any-throw-exception/26935/1 "2015-03-29T01:37:59Z")

</div>

Continuing the discussion from [[solved] Badges 'update daily' won't trigger](https://meta.discourse.org/t/solved-badges-update-daily-wont-trigger/25659/3):

> [@\[solved\] Badges 'update daily' won't trigger](https://meta.discourse.org/t/solved-badges-update-daily-wont-trigger/25659/3):
>
> /sidekiq/scheduler : Jobs::BadgeGrant FAILED  
> /logs:  
> Job exception: PG::UniqueViolation: ERROR: duplicate key value violates unique constraint “index\_user\_badges\_on\_badge\_id\_and\_user\_id\_and\_seq”  
> DETAIL: Key (badge\_id, user\_id, seq)=(104, 1, 0) already exists.
> 
> Thanks, problem solved (by adding DISTINCT ON for user\_id of another badge)

---

<div class="post-metadata">

**Author:** ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)\
**Post date:** [2015年二月25日 19:53 UTC](https://meta.discourse.org/t/badge-grant-fails-if-any-throw-exception/26935/2 "2015-02-25T19:53:07Z")

</div>

@sam it’s bad that one rogue query can stop all the daily badges, people should get a /admin alert for this

---

<div class="post-metadata">

**Author:** ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)\
**Post date:** [2015年二月25日 21:30 UTC](https://meta.discourse.org/t/badge-grant-fails-if-any-throw-exception/26935/3 "2015-02-25T21:30:10Z")

</div>

Sure PR to fix this welcome, we should also be logging warnings for any “delta” query that takes longer than 200ms and daily that takes longer than 2 seconds (configurable in site settings)

---

<div class="post-metadata">

**Author:** ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)\
**Post date:** [2015年三月29日 01:36 UTC](https://meta.discourse.org/t/badge-grant-fails-if-any-throw-exception/26935/4 "2015-03-29T01:36:48Z")

</div>

[https://github.com/discourse/discourse/pull/3306](https://github.com/discourse/discourse/pull/3306)

No /admin alert, logging of long queries not included

---

<div class="post-metadata">

**Author:** ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)\
**Post date:** [2017年十一月23日 21:55 UTC](https://meta.discourse.org/t/badge-grant-fails-if-any-throw-exception/26935/5 "2017-11-23T21:55:16Z")

</div>


