简体   繁体   中英

How to increase variable every Sunday in Rails 3?

I need to increase value of some counter every Sunday.

I know, that I can get if today is Sunday, by this code:

def count
 @counter = 27226
  if Time.now.sunday?
    @counter +=315
  end
end

but it will be increased ONLY on Sunday and on other day it will be the same, not increased.

Can someone help me ?

Windows does not have cron, but it does have an equivalent task scheduler.

See this overview of the scheduler and this specific example for configuring a "Wednesday-only" task.

A counter like you are describing does seem like the kind of value that you would normally store in a database, eg SQLite is lightweight/convenient. You could take a look at this nice intro on SQLite in Windows .

Update

In answer to your question in the comments...

so I can run .rb file or ruby task with this ?

Yes, you can. Here is a small recipe:

1) Install Ruby with this installer: http://rubyinstaller.org/ Note: Make sure to check the checkboxes that set it up to be able to run standalone Ruby scripts as-is.

2) Write a sample ruby script to periodically run. Eg, here's one that will throw a Windows dialog:

require 'Win32API'
title = "Test"
text = "Testing..."
dialog = Win32API.new('user32', 'MessageBox', 'LPPL', 'I')
result = dialog.call(0, text, title, 1)

3) And here's an example of "cron" setup from cmd.exe: schtasks /create /sc minute /mo 1 /tn "Test Script" /tr c:\\Users\\manzoid\\dev\\test.rb

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM