Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
48 lines (32 sloc) 1.18 KB

PeriodicCounter

Maintains period fields on any counter column in your database

Requirements

sudo gem install periodic_counter

Create columns

You should already have a counter column (let's call it X) that is being incremented by some external process.

Add an X_data varchar column with a length of 2048.

Add your periodic counters (all integers):

  • X_last_week
  • X_last_6_hours
  • X_last_sunday
  • X_2_days_ago

Currently only days of the week and ActiveSupport's time extensions are supported for time periods. If no digit is present, "1" is assumed.

Create configuration

Create a file, config/counters.yml:

my_table_name:
  - my_counter

The plugin assumes that the config directory also houses your database.yml file.

Create cron entry

Add the following command to your crontab at a period of your choosing:

cd /path/to/your/app && RAILS_ENV=production periodic_counter