Class: Rapns::Daemon::Batch

Inherits:
Object
  • Object
show all
Includes:
Reflectable
Defined in:
lib/rapns/daemon/batch.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Reflectable

#reflect

Constructor Details

#initialize(notifications) ⇒ Batch

Returns a new instance of Batch.



9
10
11
12
13
14
15
16
# File 'lib/rapns/daemon/batch.rb', line 9

def initialize(notifications)
  @notifications = notifications
  @num_processed = 0
  @delivered = []
  @failed = {}
  @retryable = {}
  @mutex = Mutex.new
end

Instance Attribute Details

#deliveredObject (readonly)

Returns the value of attribute delivered.



6
7
8
# File 'lib/rapns/daemon/batch.rb', line 6

def delivered
  @delivered
end

#failedObject (readonly)

Returns the value of attribute failed.



6
7
8
# File 'lib/rapns/daemon/batch.rb', line 6

def failed
  @failed
end

#notificationsObject (readonly)

Returns the value of attribute notifications.



6
7
8
# File 'lib/rapns/daemon/batch.rb', line 6

def notifications
  @notifications
end

#num_processedObject (readonly)

Returns the value of attribute num_processed.



6
7
8
# File 'lib/rapns/daemon/batch.rb', line 6

def num_processed
  @num_processed
end

#retryableObject (readonly)

Returns the value of attribute retryable.



6
7
8
# File 'lib/rapns/daemon/batch.rb', line 6

def retryable
  @retryable
end

Instance Method Details

#complete?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/rapns/daemon/batch.rb', line 56

def complete?
  @complete == true
end

#describeObject



60
61
62
# File 'lib/rapns/daemon/batch.rb', line 60

def describe
  @notifications.map(&:id).join(', ')
end

#mark_delivered(notification) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/rapns/daemon/batch.rb', line 31

def mark_delivered(notification)
  if Rapns.config.batch_storage_updates
    @delivered << notification
  else
    Rapns::Daemon.store.mark_delivered(notification)
  end
end

#mark_failed(notification, code, description) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/rapns/daemon/batch.rb', line 39

def mark_failed(notification, code, description)
  if Rapns.config.batch_storage_updates
    key = [code, description]
    @failed[key] ||= []
    @failed[key] << notification
  else
    Rapns::Daemon.store.mark_failed(notification, code, description)
  end
end

#mark_retryable(notification, deliver_after) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/rapns/daemon/batch.rb', line 22

def mark_retryable(notification, deliver_after)
  if Rapns.config.batch_storage_updates
    @retryable[deliver_after] ||= []
    @retryable[deliver_after] << notification
  else
    Rapns::Daemon.store.mark_retryable(notification, deliver_after)
  end
end

#notification_processedObject



49
50
51
52
53
54
# File 'lib/rapns/daemon/batch.rb', line 49

def notification_processed
  @mutex.synchronize do
    @num_processed += 1
    complete if @num_processed >= @notifications.size
  end
end

#num_notificationsObject



18
19
20
# File 'lib/rapns/daemon/batch.rb', line 18

def num_notifications
  @notifications.size
end