# Running a ruby script once a week automatically

**URL:** <https://www.ruby-forum.com/t/running-a-ruby-script-once-a-week-automatically/72023>\
**Category:** Ruby\
**Created:** [October 13, 2006, 5:41pm UTC](https://www.ruby-forum.com/t/running-a-ruby-script-once-a-week-automatically/72023 "2006-10-13T17:41:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jotto](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/eada6e/32.png) [@jotto](https://www.ruby-forum.com/u/jotto)\
**Post date:** [October 13, 2006, 5:41pm UTC](https://www.ruby-forum.com/t/running-a-ruby-script-once-a-week-automatically/72023/1 "2006-10-13T17:41:35Z")

</div>

I have a SQL query that examines an entire column (right now 25,000  
rows, but growing fast), it finds the top 50 most common elements in a  
column. To reduce load, I want to execute this script only once a week  
instead of every time the page is loaded.

What is the best way to do this? Just run a cron job that executes a  
Ruby script once a week? Or does MySQL have something built in for this?

---

<div class="post-metadata">

**Author:** ![jotto](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/eada6e/32.png) [@jotto](https://www.ruby-forum.com/u/jotto)\
**Post date:** [October 13, 2006, 10:31pm UTC](https://www.ruby-forum.com/t/running-a-ruby-script-once-a-week-automatically/72023/2 "2006-10-13T22:31:31Z")

</div>

> What is the best way to do this? Just run a cron job that executes a  
> Ruby script once a week? Or does MySQL have something built in for this?

I have the same situation with scripts, cron is a right choice.

---

<div class="post-metadata">

**Author:** ![jotto](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/eada6e/32.png) [@jotto](https://www.ruby-forum.com/u/jotto)\
**Post date:** [October 14, 2006, 12:05pm UTC](https://www.ruby-forum.com/t/running-a-ruby-script-once-a-week-automatically/72023/3 "2006-10-14T12:05:45Z")

</div>

jotto [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have a SQL query that examines an entire column (right now 25,000  
> rows, but growing fast), it finds the top 50 most common elements in a  
> column. To reduce load, I want to execute this script only once a week  
> instead of every time the page is loaded.

What exactly do you mean by “every time the page is loaded”? Is this  
some  
kind of web application? Are you using some kind of framework?

> What is the best way to do this? Just run a cron job that executes a  
> Ruby script once a week? Or does MySQL have something built in for  
> this?

I don’t know MySQL - it probably has. An alternative approach is to use  
cron to schedule your script and have the script write the result of  
processing in a table inside your DB. The “page” can then read from  
that  
instead of triggering the complex process every time. HTH

Kind regards

```
robert

```
