-
Notifications
You must be signed in to change notification settings - Fork 0
/
web.rb
63 lines (48 loc) · 1.33 KB
/
web.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require 'sinatra'
require 'iron_cache'
require 'iron_worker_ng'
require 'twilio-ruby'
use Rack::Logger
helpers do
def puts(msg)
request.logger.info msg
end
end
get '/' do
erb :index
end
get '/start' do
number = params[:number]
config = YAML.load_file("config/config.yml")
config_iron = JSON.parse(File.read("workers/iron.json"))
worker_client = IronWorkerNG::Client.new(:token => config_iron['token'], :project_id => config_iron['project_id'])
cache_client = IronCache::Client.new(:token => config_iron['token'], :project_id => config_iron['project_id'])
cache = cache_client.cache("affirmation-#{number}")
load_schedule(cache)
cache.put("day", 0)
worker_client.schedules.create('Affirmation',
{
:number => number,
:config => worker_client.api.options
},
{
:start_at => Time.now,
:run_times => 31,
:run_every => 86400
})
redirect '/done'
end
get '/done' do
erb :done
end
private
def load_schedule(cache)
puts "Loading Cache Up...."
i=0
File.open('lists/affirmations.txt', 'r') do |f|
while line = f.gets
cache.put(i.to_s, line)
i+=1
end
end
end