-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.rb
56 lines (45 loc) · 1.64 KB
/
server.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
require 'sinatra/base'
require 'sinatra/reloader'
require 'sinatra/activerecord'
require 'sidekiq'
require 'sidekiq/api'
require 'sidekiq/web'
require 'json'
require './pusher.rb'
class Server < Sinatra::Base
register Sinatra::ActiveRecordExtension
configure :development do
register Sinatra::Reloader
end
get '/' do
stats = Sidekiq::Stats.new
workers = Sidekiq::Workers.new
"
<p>Processed: #{stats.processed}</p>
<p>In Progress: #{workers.size}</p>
<p>Enqueued: #{stats.enqueued}</p>
<p><a href='/'>Refresh</a></p>
<p><a href='/sidekiq'>Dashboard</a></p>
"
end
post '/schedule' do
content_type :json
begin
raise ArgumentError('Platform argument is required') unless params.include?('platform')
raise ArgumentError('Platform is not apns, gcm, adm or wpns.') unless %w(apns gcm adm wpns).include?(params['platform'])
raise ArgumentError('Application argument is required') unless params.include?('app')
raise ArgumentError('Device argument is required') unless params.include?('device')
raise ArgumentError('Date argument is required') unless params.include?('date')
date = Time.at(params['date'].to_i)
platform = params['platform']
app = params['app']
device = params['device']
message = params.include?('message') ? params['message'] : nil
data = params.include?('data') ? params['data'] : nil
Pusher.perform_at(date.to_i, platform, app, device, message, data)
rescue Exception => e
return {result: 'ko', error: e.to_s}.to_json
end
{result: 'ok'}.to_json
end
end