rooftop-spektrix_sync 0.0.2.15 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bb6fd037cce26a2e0f142bf431ef45fc4c1989a9
4
- data.tar.gz: a7a3bb0ae24fe58aa5c0d8af3b3f51e8d8a2091e
3
+ metadata.gz: 0c6ea7f937c20f6eeaefb7b45d6bd032002f63f1
4
+ data.tar.gz: e8eac4c9b5e0be2a7292464f7b92328f6c03d25d
5
5
  SHA512:
6
- metadata.gz: b4d00862c48da22fc7cb8dface4fba4b0a9546d2ce964427d9dc59a83a715cf9073f3f21e25f05b23cd89151cf454b20d401a8c97db3d38232d5a36c9ec98ec4
7
- data.tar.gz: 129902d9ea10654f3d6737bc759154306256286a408810a15c12dd8bbc8c9c044f7031b0a3ed4e1ea34891e366ee5b9d07d960815a7e089db29fa17331d2951c
6
+ metadata.gz: 363820205f2eb78e34c589ea37e01b763b03c44e1f62f92cd75a42582129f4daf10d07e1a1f4ff7f17b02d1b81d46114c88d64a22f468f6ffac85865224e797d
7
+ data.tar.gz: 917bb08292a2ce12af2288c70f624a05c44ab25d0f3a2a3839d48e7c150b82afdec24e588249ee036b1562b8151a48ee390501a3ff7d24f50b7d45e6c5d4d425
@@ -2,6 +2,7 @@ module Rooftop
2
2
  module SpektrixSync
3
3
  class EventSync
4
4
  attr_reader :spektrix_event,
5
+ :spektrix_instance_statuses,
5
6
  :rooftop_event,
6
7
  :rooftop_price_lists,
7
8
  :logger
@@ -13,6 +14,9 @@ module Rooftop
13
14
  @spektrix_event = spektrix_event
14
15
  @rooftop_event = @rooftop_events.find {|e| e.meta_attributes[:spektrix_id].try(:to_i) == @spektrix_event.id.to_i}
15
16
  @rooftop_price_lists = sync_task.rooftop_price_lists
17
+ @sync_task = sync_task
18
+ @logger.info("Fetching all instance statuses for event")
19
+ @spektrix_instance_statuses = Spektrix::Events::InstanceStatus.where(event_id: @spektrix_event.id, all: true).to_a
16
20
  end
17
21
 
18
22
  def sync_to_rooftop
@@ -20,36 +24,64 @@ module Rooftop
20
24
  # find the event
21
25
  @rooftop_event ||= Rooftop::Events::Event.new({
22
26
  title: @spektrix_event.title,
23
- content: {basic: {content: @spektrix_event.description}},
27
+ content: {
28
+ basic: {
29
+ content: @sync_task.options[:import_spektrix_description] ? @spektrix_event.description : ""
30
+ }
31
+ },
24
32
  meta_attributes: {},
25
33
  status: nil
26
34
  })
27
35
  sync()
28
36
  rescue => e
29
- @logger.error(e.to_s)
37
+ @logger.fatal(e.to_s)
30
38
  end
31
39
  end
32
40
 
33
41
  def sync
34
42
  update_meta_attributes
35
43
  update_on_sale
36
- if @rooftop_event.persisted?
37
- # Ensure we're not overwriting newer stuff in RT with older stuff from this sync by
38
- # removing the title and content if this is a PUT request (i.e. it already exists in RT)
39
- @rooftop_event.restore_title!
40
- @rooftop_event.restore_content!
41
- @rooftop_event.restore_slug!
42
- @rooftop_event.restore_link!
43
- @rooftop_event.restore_event_instance_availabilities!
44
- end
45
44
 
46
- if @rooftop_event.save!
47
- @logger.debug("Saved event: #{@rooftop_event.title} #{@rooftop_event.id}")
48
- sync_instances
45
+ sync_event_instances = true
46
+
47
+ if event_requires_sync?
48
+ @rooftop_event.meta_attributes[:spektrix_hash] = generate_spektrix_hash(@spektrix_event)
49
+ rooftop_event_title = @rooftop_event.title
50
+
51
+ new_event = !@rooftop_event.persisted?
52
+ if @rooftop_event.persisted?
53
+ # Ensure we're not overwriting newer stuff in RT with older stuff from this sync by
54
+ # removing the title and content if this is a PUT request (i.e. it already exists in RT)
55
+ @rooftop_event.restore_title!
56
+ @rooftop_event.restore_content!
57
+ @rooftop_event.restore_slug!
58
+ @rooftop_event.restore_link!
59
+ @rooftop_event.restore_event_instance_availabilities!
60
+ end
61
+
62
+ if @rooftop_event.save!
63
+ @logger.info("#{new_event ? 'Created' : 'Saved'} event: #{rooftop_event_title} #{@rooftop_event.id}")
64
+ else
65
+ sync_event_instances = false
66
+ end
67
+ else
68
+ @logger.info("Skipping event update")
49
69
  end
70
+
71
+ sync_instances if sync_event_instances
50
72
  end
51
73
 
52
74
  private
75
+ def event_requires_sync?
76
+ rooftop_event_hash = @rooftop_event.meta_attributes['spektrix_hash']
77
+
78
+ @rooftop_event.id.nil? || !rooftop_event_hash || rooftop_event_hash != generate_spektrix_hash(@spektrix_event)
79
+ end
80
+
81
+ def generate_spektrix_hash(event)
82
+ Digest::MD5.hexdigest(event.attributes.to_s)
83
+ end
84
+
53
85
  def update_meta_attributes
54
86
  @rooftop_event.meta_attributes ||= {}
55
87
  @rooftop_event.meta_attributes[:spektrix_id] = @spektrix_event.id
@@ -70,21 +102,46 @@ module Rooftop
70
102
  def sync_instances
71
103
  @rooftop_instances = @rooftop_event.instances.to_a
72
104
  @spektrix_instances = @spektrix_event.instances.to_a
105
+ @logger.info("\tChecking #{@rooftop_instances.size} instances..")
106
+
107
+ synced_to_rooftop = [] # array of event instance id's that were updated/created on RT
108
+
109
+ # delete any RT instances that aren't included in the set of spektrix event instances
110
+ rooftop_instance_spektrix_ids = @rooftop_instances.collect{|i| i.meta_attributes[:spektrix_id]}.compact
111
+ spektrix_instance_ids = @spektrix_instances.collect(&:id)
112
+ delete_instance_ids = rooftop_instance_spektrix_ids - spektrix_instance_ids
113
+ delete_instances = @rooftop_instances.select{|i| delete_instance_ids.include?(i.meta_attributes[:spektrix_id])}
114
+ # before we can call .destroy on an instance, we need to mutate the object so it has an :event_id to hit the proper destroy method endpoint...
115
+ delete_instances.each do |instance|
116
+ @logger.info("Deleting Rooftop Instance #{instance.id}")
117
+ instance.tap{|i| i.event_id = @rooftop_event.meta_attributes[:spektrix_id]}.destroy
118
+ end
119
+
73
120
  @spektrix_instances.each_with_index do |instance, i|
121
+ @logger.info("Instance #{instance.id}")
74
122
  begin
75
123
  tries ||= 2
76
124
  instance_sync = Rooftop::SpektrixSync::InstanceSync.new(instance, self)
77
- instance_sync.sync
78
- rescue
79
- retry unless (tries -= 1 ).zero?
125
+ synced_to_rooftop << instance_sync.sync
126
+ rescue => e
127
+ if (tries -= 1).zero?
128
+ @logger.fatal("Not retrying... #{e}")
129
+ else
130
+ @logger.warn("Retrying... #{e}")
131
+ retry
132
+ end
80
133
  end
81
134
  end
82
135
 
83
- update_event_metadata unless @rooftop_instances.empty?
136
+ # if we have any updated event instances, send the POST /events/$event-instance/update_metadata request
137
+ # to trigger the event meta data update on Rooftop (sets first/last event instance dates on an event to aid in filtering and sorting)
138
+ if synced_to_rooftop.compact.any?
139
+ update_event_metadata
140
+ end
84
141
  end
85
142
 
86
143
  def update_event_metadata
87
- @logger.debug("Saved event instances. Updating event metadata")
144
+ @logger.info("Saved event instances. Updating event metadata")
88
145
  Rooftop::Events::Event.post("#{@rooftop_event.class.collection_path}/#{@rooftop_event.id}/update_metadata")
89
146
  end
90
147
  end
@@ -3,6 +3,7 @@ module Rooftop
3
3
  class InstanceSync
4
4
 
5
5
  def initialize(spektrix_instance, event_sync)
6
+ @spektrix_instance_statuses = event_sync.spektrix_instance_statuses
6
7
  @spektrix_event = event_sync.spektrix_event
7
8
  @rooftop_event = event_sync.rooftop_event
8
9
  @logger = event_sync.logger
@@ -19,18 +20,40 @@ module Rooftop
19
20
  end
20
21
  update_price
21
22
  if @rooftop_instance.price_list_id.nil?
22
- @logger.warn("No price list for Spektrix instance id #{@spektrix_instance.id}")
23
+ @logger.error("No price list for Spektrix instance id #{@spektrix_instance.id}")
23
24
  return
24
25
  end
25
26
  update_meta_attributes
26
27
  update_availability
27
28
  update_on_sale
28
- if @rooftop_instance.save!
29
- @logger.debug("#{instance_updated ? "Updated" : "Created"} Rooftop instance #{@rooftop_instance.id}")
29
+
30
+ if event_instance_requires_sync?
31
+ @rooftop_instance.meta_attributes[:spektrix_hash] = generate_spektrix_hash(@spektrix_instance)
32
+
33
+ if @rooftop_instance.save!
34
+ @logger.info("#{instance_updated ? "Updated" : "Created"} Rooftop instance #{@rooftop_instance.id}")
35
+ return @rooftop_instance.id
36
+ else
37
+ @logger.info("\n\nCouldn't save instance\n\n")
38
+ end
39
+ else
40
+ @logger.info("Skipping event instance save - computed hash matched")
41
+ return nil
30
42
  end
31
43
  end
32
44
 
33
45
  private
46
+ def event_instance_requires_sync?
47
+ rooftop_event_instance_hash = @rooftop_instance.meta_attributes['spektrix_hash']
48
+
49
+ @rooftop_instance.id.nil? || !rooftop_event_instance_hash || rooftop_event_instance_hash != generate_spektrix_hash(@spektrix_instance)
50
+ end
51
+
52
+ def generate_spektrix_hash(event_instance)
53
+ instance_status = @spektrix_instance_statuses.find{|is| is.instance[:id] == @spektrix_instance.id} || @spektrix_instance.status
54
+ Digest::MD5.hexdigest(event_instance.attributes.to_s + instance_status.attributes.to_s)
55
+ end
56
+
34
57
  def find_rooftop_instance_by_spektrix_id(spektrix_id)
35
58
  @rooftop_event.instances.to_a.find {|i| i.meta_attributes[:spektrix_id] == spektrix_id }
36
59
  end
@@ -40,7 +63,7 @@ module Rooftop
40
63
  end
41
64
 
42
65
  def update_meta_attributes
43
- @rooftop_instance.meta_attributes = @spektrix_instance.custom_attributes.merge(spektrix_id: @spektrix_instance.id)
66
+ @rooftop_instance.meta_attributes = @spektrix_instance.custom_attributes.merge(spektrix_id: @spektrix_instance.id, spektrix_hash: @rooftop_instance.meta_attributes.try(:[], :spektrix_hash))
44
67
  end
45
68
 
46
69
  def update_on_sale
@@ -58,12 +81,14 @@ module Rooftop
58
81
  end
59
82
 
60
83
  def update_availability
84
+ instance_status = @spektrix_instance_statuses.find{|is| is.instance[:id] == @spektrix_instance.id} || @spektrix_instance.status
85
+
61
86
  availability = {
62
87
  availability: {
63
88
  starts_at: @spektrix_instance.start.iso8601,
64
89
  stops_at: @spektrix_instance.start.advance(seconds: @rooftop_event.meta_attributes[:duration]),
65
- seats_capacity: @spektrix_instance.status.capacity,
66
- seats_available: @spektrix_instance.status.available
90
+ seats_capacity: instance_status.capacity,
91
+ seats_available: instance_status.available
67
92
  }
68
93
  }
69
94
  @rooftop_instance.title = @rooftop_event.title + ": " + @spektrix_instance.start.strftime("%d %b %Y %H:%M")
@@ -22,8 +22,12 @@ module Rooftop
22
22
  # begin
23
23
  @spektrix_price_lists.each do |spektrix_price_list|
24
24
  # Don't bother syncing a price list where none of the prices have bands.
25
+ if spektrix_price_list.prices.nil?
26
+ @logger.error("Spektrix price list ID #{spektrix_price_list.id} has no prices at all")
27
+ next
28
+ end
25
29
  if spektrix_price_list.prices.select {|p| !p.band.nil?}.empty?
26
- @logger.warn("Spektrix price list ID #{spektrix_price_list.id} has prices with missing bands.")
30
+ @logger.error("Spektrix price list ID #{spektrix_price_list.id} has prices with missing bands.")
27
31
  end
28
32
 
29
33
  # find or create a price list
@@ -33,22 +37,22 @@ module Rooftop
33
37
  new_price_list = @rooftop_price_list.new?
34
38
  # save the price list to rooftop
35
39
  if @rooftop_price_list.save!
36
- @logger.debug("#{new_price_list ? "Created" : "Updated"} price list #{spektrix_price_list.id}")
40
+ @logger.info("#{new_price_list ? "Created" : "Updated"} price list #{spektrix_price_list.id}")
37
41
  sync_prices(spektrix_price_list, @rooftop_price_list)
38
42
  end
39
43
  end
40
44
  # rescue => e
41
- # @logger.warn(e.to_s)
45
+ # @logger.error(e.to_s)
42
46
  # end
43
47
  end
44
48
 
45
49
  def sync_prices(spektrix_price_list, rooftop_price_list)
46
50
  # begin
47
51
  spektrix_price_list.prices.each_with_index do |spektrix_price, i |
48
- @logger.debug("syncing price #{i+1} / #{spektrix_price_list.prices.count}")
52
+ @logger.info("syncing price #{i+1} / #{spektrix_price_list.prices.count}")
49
53
  # skip ones without a band
50
54
  if spektrix_price.band.nil?
51
- @logger.warn("Spektrix price list ID: #{spektrix_price_list.id}: Price #{spektrix_price.price} with ticket type #{spektrix_price.ticket_type.name} does not have a band")
55
+ @logger.error("Spektrix price list ID: #{spektrix_price_list.id}: Price #{spektrix_price.price} with ticket type #{spektrix_price.ticket_type.name} does not have a band")
52
56
  next
53
57
  end
54
58
  current_rooftop_price = find_rooftop_price(rooftop_price_list, spektrix_price)
@@ -58,16 +62,28 @@ module Rooftop
58
62
  new_price.assign_attributes(current_rooftop_price.attributes)
59
63
  end
60
64
 
65
+ ticket_type_id = find_rooftop_ticket_type(spektrix_price).try(:id)
66
+ price_band_id = find_rooftop_price_band(spektrix_price).try(:id)
67
+ if ticket_type_id.nil?
68
+ @logger.error("Ticket type for spektrix price #{spektrix_price.price} with ticket type #{spektrix_price.ticket_type.name} is nil")
69
+ next
70
+ end
71
+
72
+ if price_band_id.nil?
73
+ @logger.error("Price band for spektrix price #{spektrix_price.price} with ticket type #{spektrix_price.ticket_type.name} is nil")
74
+ next
75
+ end
76
+
61
77
  new_price.meta_attributes = {
62
78
  is_band_default: (spektrix_price.is_band_default == "true"),
63
- ticket_type_id: find_rooftop_ticket_type(spektrix_price).id,
64
- price_band_id: find_rooftop_price_band(spektrix_price).id,
79
+ ticket_type_id: ticket_type_id,
80
+ price_band_id: price_band_id,
65
81
  ticket_price: spektrix_price.price.to_f
66
82
  }
67
83
 
68
84
  new_price.title = "#{spektrix_price.band.name} (£#{new_price.meta_attributes[:ticket_price]})"
69
85
  if new_price.save!
70
- @logger.debug("Spektrix price list ID: #{spektrix_price_list.id}: Saved price £#{new_price.meta_attributes[:ticket_price]} with ticket type #{spektrix_price.ticket_type.name} for price band #{spektrix_price.band.name}")
86
+ @logger.error("Spektrix price list ID: #{spektrix_price_list.id}: Saved price £#{new_price.meta_attributes[:ticket_price]} with ticket type #{spektrix_price.ticket_type.name} for price band #{spektrix_price.band.name}")
71
87
  end
72
88
  end
73
89
  # rescue => e
@@ -85,11 +101,11 @@ module Rooftop
85
101
  end
86
102
  Rooftop::Events::PriceList.where(post__in: rooftop_ids_to_remove).each do |pricelist|
87
103
  if pricelist.destroy
88
- @logger.debug("Removed rooftop price list #{id} which didn't exist in spektrix")
104
+ @logger.info("Removed rooftop price list #{id} which didn't exist in spektrix")
89
105
  end
90
106
  end
91
107
  rescue => e
92
- @logger.error(e.to_s)
108
+ @logger.fatal(e.to_s)
93
109
  end
94
110
  end
95
111
 
@@ -10,11 +10,16 @@ module Rooftop
10
10
  :rooftop_price_bands,
11
11
  :options
12
12
 
13
- PIDPATH = "/tmp/rooftop-spektrix-sync.pid"
13
+ PIDFILE = ARGV.find{|a| a=~/pidname=[^$]+/}.try(:split, '=').try(:last) || 'sync'
14
+ PIDPATH = "/tmp/rooftop-spektrix-#{PIDFILE}.pid"
14
15
 
15
16
  def initialize(starting_at, opts={})
17
+ if defined?(Rooftop::Rails)
18
+ Rooftop::Rails.configuration.perform_object_caching = false
19
+ end
20
+
16
21
  begin
17
- Rooftop.preview = true
22
+ Rooftop.include_drafts = true
18
23
  if defined?(Rooftop::Rails)
19
24
  Rooftop::Rails.configuration.perform_object_caching = false
20
25
  end
@@ -26,39 +31,47 @@ module Rooftop
26
31
  import_prices: false,
27
32
  import_events: true,
28
33
  delete_orphan_events: false,
29
- accept_empty_rooftop_events: false
34
+ accept_empty_rooftop_events: false,
35
+ import_spektrix_description: true
30
36
  }
31
37
  @options = default_opts.merge!(opts)
32
- @logger.debug("*************************************************************************")
33
- @logger.debug("Running with options: #{@options.select {|k,v| k if v}.keys.join(", ")}")
34
- @logger.debug("*************************************************************************")
38
+ @logger.info("*************************************************************************")
39
+ @logger.info("Running with options: #{@options.select {|k,v| k if v}.keys.join(", ")}")
40
+ @logger.info("*************************************************************************")
35
41
  rescue => e
36
- @logger.error("Couldn't start sync: #{e}")
42
+ @logger.fatal("Couldn't start sync: #{e}")
37
43
  end
38
44
  end
39
45
 
40
46
  def fetch_rooftop_and_spektrix_data
41
- @logger.debug("Fetching all Spektrix events")
42
47
  @spektrix_events = @spektrix_events.present? ? @spektrix_events : Spektrix::Events::Event.all(instance_start_from: @starting_at.iso8601).to_a
43
48
  if @options[:spektrix_event_id]
49
+ @logger.info("Selecting single Spektrix event")
44
50
  @spektrix_events = @spektrix_events.select {|e| e.id == @options[:spektrix_event_id].to_s}
51
+ else
52
+ @logger.info("Fetching all Spektrix events")
45
53
  end
46
- @logger.debug("Fetching all Rooftop events")
54
+
55
+ @logger.info("Fetching all Rooftop events")
47
56
  @rooftop_events = Rooftop::Events::Event.all.to_a
48
57
  unless @options[:accept_empty_rooftop_events]
58
+ @logger.info("No Rooftop events")
49
59
  raise StandardError, "Rooftop returned an empty set of events which is probably wrong" if @rooftop_events.empty?
50
60
  end
51
- @logger.debug("Fetching all Spektrix price lists")
61
+ @logger.info("Fetching all Spektrix price lists")
52
62
  @spektrix_price_lists = @spektrix_price_lists.present? ? @spektrix_price_lists : Spektrix::Tickets::PriceList.all.to_a
53
- @logger.debug("Fetching all Rooftop Price lists")
63
+ @logger.info("Fetching all Rooftop Price lists")
54
64
  @rooftop_price_lists = Rooftop::Events::PriceList.all.to_a
55
- @logger.debug("Fetching all Rooftop ticket types")
56
- @rooftop_ticket_types = Rooftop::Events::TicketType.all.to_a
57
- @logger.debug("Fetching all Rooftop price bands")
58
- @rooftop_price_bands = Rooftop::Events::PriceBand.all.to_a
59
- end
60
-
61
65
 
66
+ if @options[:import_price_bands] || @options[:import_ticket_types] || @options[:import_prices]
67
+ @logger.info("Fetching all Spektrix price lists")
68
+ @spektrix_price_lists = @spektrix_price_lists.present? ? @spektrix_price_lists : Spektrix::Tickets::PriceList.all.to_a
69
+ @logger.info("Fetching all Rooftop ticket types")
70
+ @rooftop_ticket_types = Rooftop::Events::TicketType.all.to_a
71
+ @logger.info("Fetching all Rooftop price bands")
72
+ @rooftop_price_bands = Rooftop::Events::PriceBand.all.to_a
73
+ end
74
+ end
62
75
 
63
76
  def self.run(starting_at=nil, opts={})
64
77
  sync_pid = Process.get_pid(Rooftop::SpektrixSync::SyncTask::PIDPATH)
@@ -75,29 +88,29 @@ module Rooftop
75
88
  Process.remove_pidfile(Rooftop::SpektrixSync::SyncTask::PIDPATH)
76
89
  end
77
90
 
78
- def self.run_events_import(starting_at=nil, event_id=nil)
79
- opts = event_id.present? ? {spektrix_event_id: event_id} : {}
91
+ def self.run_events_import(starting_at=nil, event_id=nil, opts={})
92
+ opts = event_id.present? ? opts.merge({spektrix_event_id: event_id}) : opts
80
93
  self.run(starting_at, opts)
81
94
  end
82
95
 
83
- def self.run_full_import(starting_at=nil)
96
+ def self.run_full_import(starting_at=nil, opts={})
84
97
  self.run(starting_at, {
85
98
  import_price_bands: true,
86
99
  import_ticket_types: true,
87
100
  import_prices: true,
88
101
  import_events: true,
89
102
  delete_orphan_events: false
90
- })
103
+ }.merge(opts))
91
104
  end
92
105
 
93
- def self.run_prices_import(starting_at=nil)
106
+ def self.run_prices_import(starting_at=nil, opts={})
94
107
  self.run(starting_at, {
95
108
  import_price_bands: true,
96
109
  import_ticket_types: true,
97
110
  import_prices: true,
98
111
  import_events: false,
99
112
  delete_orphan_events: false
100
- })
113
+ }.merge(opts))
101
114
  end
102
115
 
103
116
 
@@ -125,7 +138,7 @@ module Rooftop
125
138
  # delete_orphan_spektrix_events
126
139
  # end
127
140
  rescue => e
128
- @logger.error(e)
141
+ @logger.fatal(e)
129
142
  end
130
143
 
131
144
  end
@@ -136,13 +149,17 @@ module Rooftop
136
149
  begin
137
150
  tries ||= 2
138
151
  @spektrix_events.each_with_index do |event, i|
139
- @logger.debug("Sync #{i+1} / #{@spektrix_events.length}: #{event.title}")
152
+ @logger.info("Sync #{i+1} / #{@spektrix_events.length}: #{event.title}")
140
153
  item = EventSync.new(event, self)
141
154
  item.sync_to_rooftop
142
155
  end
143
156
  rescue => e
144
- @logger.error(e.to_s)
145
- retry unless (tries -= 1).zero?
157
+ if (tries -= 1).zero?
158
+ @logger.fatal("Not retrying...#{e.to_s}")
159
+ else
160
+ @logger.error("Retrying...#{e.to_s}")
161
+ retry
162
+ end
146
163
  end
147
164
  end
148
165
 
@@ -159,7 +176,7 @@ module Rooftop
159
176
  Rooftop::Events::Event.where(post__in: rooftop_ids_to_delete).each do |rooftop_event|
160
177
  title = rooftop_event.title
161
178
  if rooftop_event.destroy
162
- @logger.debug("Removed Rooftop event #{title} which doesn't exist in Spektrix")
179
+ @logger.info("Removed Rooftop event #{title} which doesn't exist in Spektrix")
163
180
  end
164
181
  end
165
182
  end
@@ -170,7 +187,7 @@ module Rooftop
170
187
  spektrix_bands = Spektrix::Tickets::Band.all.to_a
171
188
  # create or update existing
172
189
  spektrix_bands.each do |band|
173
- @logger.debug("Updating band #{band.name}")
190
+ @logger.info("Updating band #{band.name}")
174
191
  rooftop_band = rooftop_bands.find {|b| b.title == band.name} || Rooftop::Events::PriceBand.new
175
192
  rooftop_band.title = band.name
176
193
  rooftop_band.save!
@@ -183,7 +200,7 @@ module Rooftop
183
200
  rooftop_bands.find {|b| b.title == title}.destroy
184
201
  end
185
202
  rescue => e
186
- @logger.error(e.to_s)
203
+ @logger.fatal(e.to_s)
187
204
  end
188
205
 
189
206
 
@@ -195,7 +212,7 @@ module Rooftop
195
212
  spektrix_ticket_types = Spektrix::Tickets::Type.all.to_a
196
213
  # create or update exiting
197
214
  spektrix_ticket_types.each do |type|
198
- @logger.debug("Updating ticket type #{type.name}")
215
+ @logger.info("Updating ticket type #{type.name}")
199
216
  rooftop_ticket_type = rooftop_ticket_types.find {|t| t.title == type.name} || Rooftop::Events::TicketType.new
200
217
  rooftop_ticket_type.title = type.name
201
218
  rooftop_ticket_type.save!
@@ -208,7 +225,7 @@ module Rooftop
208
225
  rooftop_ticket_types.find {|b| b.title == title}.destroy
209
226
  end
210
227
  rescue => e
211
- @logger.error(e.to_s)
228
+ @logger.fatal(e.to_s)
212
229
  end
213
230
  end
214
231
 
@@ -3,29 +3,30 @@ namespace :rooftop do
3
3
 
4
4
  task :prepare, [:since, :logger_path] do |task, args|
5
5
  logger_path = args[:logger_path] || STDOUT
6
- Rooftop::SpektrixSync.logger = Logger.new(logger_path, 'daily')
6
+ Rooftop::SpektrixSync.logger = defined?(::Rails) ? Rails.logger : Logger.new(logger_path, 'daily')
7
7
  @since = eval(args[:since]) rescue DateTime.now
8
+ @options = eval(args[:options]) rescue {}
8
9
  end
9
10
 
10
11
 
11
12
  desc "Synchronise events from Spektrix to Rooftop"
12
- task :sync_events, [:since, :logger_path] => [:environment, :prepare] do |task, args|
13
- Rooftop::SpektrixSync::SyncTask.run_events_import(@since)
13
+ task :sync_events, [:since, :logger_path, :options] => [:environment, :prepare] do |task, args|
14
+ Rooftop::SpektrixSync::SyncTask.run_events_import(@since, nil, @options)
14
15
  end
15
16
 
16
17
  desc "Synchronise events and prices from Spektrix to Rooftop"
17
- task :sync_all, [:since, :logger_path] => [:environment, :prepare] do |task, args|
18
- Rooftop::SpektrixSync::SyncTask.run_full_import(@since)
18
+ task :sync_all, [:since, :logger_path, :options] => [:environment, :prepare] do |task, args|
19
+ Rooftop::SpektrixSync::SyncTask.run_full_import(@since, @options)
19
20
  end
20
21
 
21
22
  desc "Synchronise events and prices from Spektrix to Rooftop"
22
- task :sync_prices, [:since, :logger_path] => [:environment, :prepare] do |task, args|
23
- Rooftop::SpektrixSync::SyncTask.run_prices_import(@since)
23
+ task :sync_prices, [:since, :logger_path, :options] => [:environment, :prepare] do |task, args|
24
+ Rooftop::SpektrixSync::SyncTask.run_prices_import(@since, @options)
24
25
  end
25
26
 
26
27
  desc "Sync specific event"
27
- task :sync_event, [:spektrix_event_id, :since, :logger_path] => [:environment, :prepare] do |task, args|
28
- Rooftop::SpektrixSync::SyncTask.run_events_import(@since, args[:spektrix_event_id])
28
+ task :sync_event, [:spektrix_event_id, :since, :logger_path, :options] => [:environment, :prepare] do |task, args|
29
+ Rooftop::SpektrixSync::SyncTask.run_events_import(@since, args[:spektrix_event_id], @options)
29
30
  end
30
31
 
31
32
 
@@ -1,5 +1,5 @@
1
1
  module Rooftop
2
2
  module SpektrixSync
3
- VERSION = "0.0.2.15"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rooftop-spektrix_sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2.15
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ed Jones
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-27 00:00:00.000000000 Z
11
+ date: 2017-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler