-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
99 lines (85 loc) · 2.39 KB
/
Rakefile
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
require 'rake'
require 'spec/rake/spectask'
task :default => :spec
Spec::Rake::SpecTask.new(:spec) do |spec|
spec.spec_files = FileList['spec/**/*_spec.rb']
end
Spec::Rake::SpecTask.new(:rcov) do |spec|
spec.pattern = 'spec/**/*_spec.rb'
spec.rcov = true
end
def mail(subject, body)
require 'pony'
Pony.mail(
:to => 'holds@neco.com',
:from => 'website@neco.com',
:subject => subject,
:body => body,
:via => :smtp,
:smtp => {
:host => 'smtp.gmail.com',
:port => '587',
:user => 'website@neco.com',
:password => '060381',
:auth => :plain,
:domain => 'neco.com',
:tls => true
}
)
end
task :environment do
require 'hold'
end
desc "Sync with the exchanges"
task :sync => :environment do
begin
Account.all.each do |account|
account.sync
end
Order.all(:state => 'created').each do |order|
begin
order.sync
rescue POS::TicketsNotFound
mail('[Hold] Ticket sync failed', <<-BODY)
Could not sync tickets for order #{order.id}.
Event Name: #{order.event_name}
Event: #{order.event}
Venue: #{order.venue}
Occurs At: #{order.occurs_at.to_s}
Section: #{order.section}
Row: #{order.row}
Quantity: #{order.quantity}
Exchange: #{order.account.exchange} / #{order.account.username} / #{order.remote_id}
http://hold.neco.com/orders
BODY
end
end
Order.all(:state => 'synced').each do |order|
begin
order.hold
rescue Order::InsufficientQuantity
mail('[Hold] Could not place hold', <<-BODY)
Could not hold tickets for order #{order.id}.
A block of #{order.quantity} seats was not found.
Event Name: #{order.event_name}
Event: #{order.event}
Venue: #{order.venue}
Occurs At: #{order.occurs_at.to_s}
Section: #{order.section}
Row: #{order.row}
Quantity: #{order.quantity}
Exchange: #{order.account.exchange} / #{order.account.username} / #{order.remote_id}
http://hold.neco.com/orders
BODY
end
end
rescue
HoptoadNotifier.notify($!)
end
end
namespace :db do
desc "Automatically migrate the database"
task :migrate => :environment do
DataMapper.auto_upgrade!
end
end