# CleanUpEmailLogs job fails on having a lot of email logs

**URL:** https://meta.discourse.org/t/cleanupemaillogs-job-fails-on-having-a-lot-of-email-logs/40596
**Category:** Support
**Created:** [3월 4, 2016, 10:05오후 UTC](https://meta.discourse.org/t/cleanupemaillogs-job-fails-on-having-a-lot-of-email-logs/40596 "2016-03-04T22:05:02Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![eriko](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eriko/32/1915_2.png) [@eriko](https://meta.discourse.org/u/eriko)
#### Post date: [3월 4, 2016, 10:05오후 UTC](https://meta.discourse.org/t/cleanupemaillogs-job-fails-on-having-a-lot-of-email-logs/40596/1 "2016-03-04T22:05:02Z")

</div>

So it looks like CleanUpEmailLogs is a new Job and on at least my instance is failing at there are to many entries to nuke without the 4 gig box running out of memory. I am using the below to clear out old entries 3 days at a time.

```ruby
1000.downto(SiteSetting.delete_email_logs_after_days)
    .select.with_index { |x, idx| idx % 3 == 0 }
    .each do |n|
       threshold = n.days.ago
       puts threshold
       EmailLog.where(reply_key: nil).where("created_at < ?", threshold).destroy_all ;0
    end

```

`;0` stops the return of destroy\_all from being echoed to the terminal.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [3월 4, 2016, 11:37오후 UTC](https://meta.discourse.org/t/cleanupemaillogs-job-fails-on-having-a-lot-of-email-logs/40596/2 "2016-03-04T23:37:29Z")

</div>

Hmm this is a @zogstrip jam can you have a look Regis? Perhaps do raw SQL here if the ActiveRecords are ActingUp.. seems like a simple delete?

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [3월 4, 2016, 11:41오후 UTC](https://meta.discourse.org/t/cleanupemaillogs-job-fails-on-having-a-lot-of-email-logs/40596/3 "2016-03-04T23:41:41Z")

</div>

Yeah, I used the wrong _helper_… That should fix the issue 😉

[https://github.com/discourse/discourse/commit/05f0db0a20525a75247a442aebe120d0bfb200b0](https://github.com/discourse/discourse/commit/05f0db0a20525a75247a442aebe120d0bfb200b0)

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [3월 7, 2016, 10:24오전 UTC](https://meta.discourse.org/t/cleanupemaillogs-job-fails-on-having-a-lot-of-email-logs/40596/4 "2016-03-07T10:24:22Z")

</div>

This topic was automatically closed after 2 days. New replies are no longer allowed.
