Add scheduler

This commit is contained in:
Hakan Ensari 2017-11-09 12:59:19 +00:00
parent 3319c49dca
commit 2903015e62
9 changed files with 43 additions and 17 deletions

4
.env.example Normal file
View File

@ -0,0 +1,4 @@
LETSENCRYPT_EMAIL=foo@bar.com
LETSENCRYPT_HOST=example.com,www.example.com
RACK_ENV=production
VIRTUAL_HOST=example.com,www.example.com

View File

@ -1,4 +0,0 @@
LETSENCRYPT_EMAIL=jane@example.com
LETSENCRYPT_HOST=api.fixer.io
RACK_ENV=production
VIRTUAL_HOST=api.fixer.io

View File

@ -9,6 +9,7 @@ gem 'kgio'
gem 'oj'
gem 'rack-cors'
gem 'rake'
gem 'rufus-scheduler'
gem 'sequel_pg'
gem 'sinatra'
gem 'unicorn'

View File

@ -3,6 +3,8 @@ GEM
specs:
ast (2.3.0)
coderay (1.1.2)
et-orbi (1.0.8)
tzinfo
fixer (0.7.0)
kgio (2.11.0)
method_source (0.9.0)
@ -37,6 +39,8 @@ GEM
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.9.0)
rufus-scheduler (3.4.2)
et-orbi (~> 1.0)
sequel (5.2.0)
sequel_pg (1.8.0)
pg (>= 0.18.0)
@ -48,7 +52,10 @@ GEM
rack (~> 2.0)
rack-protection (= 2.0.0)
tilt (~> 2.0)
thread_safe (0.3.6)
tilt (2.0.8)
tzinfo (1.2.4)
thread_safe (~> 0.1)
unicode-display_width (1.3.0)
unicorn (5.3.1)
kgio (~> 2.6)
@ -68,6 +75,7 @@ DEPENDENCIES
rack-test
rake
rubocop
rufus-scheduler
sequel_pg
shotgun
sinatra

15
app/bin/schedule Executable file
View File

@ -0,0 +1,15 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
require_relative '../config/environment'
require 'rake'
require 'rufus-scheduler'
schedule = Rufus::Scheduler.new
schedule.cron '*/15 15,16,17 * * 1-5' do
load 'tasks/rates.rake'
Rake::Task['rates:update'].execute
end
schedule.join

View File

@ -10,7 +10,7 @@ module App
end
def root
Pathname.pwd
Pathname.new(File.expand_path('..', __dir__))
end
end
end

View File

@ -1,7 +0,0 @@
# frozen_string_literal: true
job_type :rake, 'cd :path && foreman run bundle exec rake :task --silent :output'
every '*/15 13,14,15,16,17 * * 1-5' do
rake 'rates:update'
end

View File

@ -1,13 +1,11 @@
# frozen_string_literal: true
namespace :rates do
task setup: :environment do
desc 'Load all rates'
task load: :environment do
require 'currency'
require 'fixer'
end
desc 'Load all rates'
task load: :setup do
Currency.db.transaction do
Currency.dataset.delete
data = Fixer::Feed.new(:historical)
@ -16,7 +14,10 @@ namespace :rates do
end
desc 'Update rates'
task update: :setup do
task update: :environment do
require 'currency'
require 'fixer'
Fixer::Feed.new.each do |hsh|
Currency.find_or_create(hsh)
end

View File

@ -15,6 +15,14 @@ services:
- '8080'
links:
- db
scheduler:
build:
context: ./app
command: bin/schedule
environment:
DATABASE_URL: postgres://postgres@db/postgres
links:
- db
nginx-proxy:
image: jwilder/nginx-proxy
volumes: