Its weird to see the time unit as below.
> repeat {
+ startTime <- now('Asia/Tokyo')
+ cat('Now is', as.character(now('Asia/Tokyo')), '(Asia/Tokyo).\n')
+ sleepTime <- startTime + 5*60 - now('Asia/Tokyo')
+ if (sleepTime > 0)
+ Sys.sleep(sleepTime)
+ }
Now is 2018-06-20 15:02:48 (Asia/Tokyo).
Now is 2018-06-20 15:02:53 (Asia/Tokyo).
Now is 2018-06-20 15:02:58 (Asia/Tokyo).
Now is 2018-06-20 15:03:03 (Asia/Tokyo).
> repeat {
+ startTime <- now('Asia/Tokyo')
+ cat('Now is', as.character(now('Asia/Tokyo')), '(Asia/Tokyo).\n')
+ sleepTime <- startTime + 120*60 - now('Asia/Tokyo')
+ if (sleepTime > 0)
+ Sys.sleep(sleepTime)
+ }
Now is 2018-06-20 15:03:21 (Asia/Tokyo).
Now is 2018-06-20 15:03:23 (Asia/Tokyo).
Now is 2018-06-20 15:03:25 (Asia/Tokyo).
Now is 2018-06-20 15:03:27 (Asia/Tokyo).
Now is 2018-06-20 15:03:29 (Asia/Tokyo).
Now is 2018-06-20 15:03:31 (Asia/Tokyo).
Now is 2018-06-20 15:03:33 (Asia/Tokyo).
Working fine now...
> repeat{
+ startTime <- now('Asia/Tokyo')
+ print(as.character(now('Asia/Tokyo')))
+ print(forecastData())
+ sleepTime <- startTime + 60*60 - now('Asia/Tokyo')
+ if (sleepTime > 0)
+ Sys.sleep(sleepTime)
+ }
[1] "2018-06-20 19:57:19"
.id ForecastDate.GMT Currency
1 EURUSD 2018-06-19 1.1756002
2 USDJPY 2018-06-19 110.4611047
3 GBPUSD 2018-06-19 1.3276902
4 USDCHF 2018-06-19 0.9869512
5 USDCAD 2018-06-19 1.2841243
6 AUDUSD 2018-06-19 0.7396868
[1] "2018-06-20 19:58:19"
.id ForecastDate.GMT Currency
1 EURUSD 2018-06-19 1.1756002
2 USDJPY 2018-06-19 110.4611047
3 GBPUSD 2018-06-19 1.3276902
4 USDCHF 2018-06-19 0.9869512
5 USDCAD 2018-06-19 1.2841243
6 AUDUSD 2018-06-19 0.7396868
[1] "2018-06-20 19:59:19"
.id ForecastDate.GMT Currency
1 EURUSD 2018-06-19 1.1756002
2 USDJPY 2018-06-19 110.4611047
3 GBPUSD 2018-06-19 1.3276902
4 USDCHF 2018-06-19 0.9869512
5 USDCAD 2018-06-19 1.2841243
6 AUDUSD 2018-06-19 0.7396868
Test the time unit for rescheduled task...
> startTime <- now('Asia/Tokyo')
> startTime + 24*60*60 - now('Asia/Tokyo')
Time difference of 24 hours