mirror of
https://github.com/hakanensari/frankfurter.git
synced 2024-11-25 04:22:28 +01:00
Add scheduler
This commit is contained in:
parent
3319c49dca
commit
2903015e62
4
.env.example
Normal file
4
.env.example
Normal 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
|
@ -1,4 +0,0 @@
|
||||
LETSENCRYPT_EMAIL=jane@example.com
|
||||
LETSENCRYPT_HOST=api.fixer.io
|
||||
RACK_ENV=production
|
||||
VIRTUAL_HOST=api.fixer.io
|
@ -9,6 +9,7 @@ gem 'kgio'
|
||||
gem 'oj'
|
||||
gem 'rack-cors'
|
||||
gem 'rake'
|
||||
gem 'rufus-scheduler'
|
||||
gem 'sequel_pg'
|
||||
gem 'sinatra'
|
||||
gem 'unicorn'
|
||||
|
@ -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
15
app/bin/schedule
Executable 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
|
@ -10,7 +10,7 @@ module App
|
||||
end
|
||||
|
||||
def root
|
||||
Pathname.pwd
|
||||
Pathname.new(File.expand_path('..', __dir__))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -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
|
@ -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
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user