Class: Parse::PushStatus

Inherits:
Object
  • Object
show all
Defined in:
lib/parse/model/classes/push_status.rb

Overview

Note:

This collection requires master key access

This class represents the data and columns contained in the standard Parse _PushStatus collection. Push status records track the delivery status and metrics of push notifications sent through Parse Server.

Push status records are created automatically when a push is sent and are updated as the push progresses through the delivery pipeline.

Status lifecycle: pending → scheduled → running → succeeded/failed

The default schema for the PushStatus class is as follows:

class Parse::PushStatus < Parse::Object
 # See Parse::Object for inherited properties...

 property :push_hash        # Unique hash identifying the push
 property :query, :object   # The query used to target installations
 property :payload, :object # The push payload that was sent
 property :source           # "rest" or "webUI"
 property :status           # "pending", "scheduled", "running", "succeeded", "failed"
 property :num_sent, :integer
 property :num_failed, :integer
 property :sent_per_type, :object
 property :failed_per_type, :object
 property :sent_per_utc_offset, :object
 property :failed_per_utc_offset, :object
 property :count, :integer  # Total installations targeted
 property :push_time, :date # When the push was/will be sent
 property :expiry, :date    # When the push expires
end

Examples:

Checking push status

status = Parse::PushStatus.find(push_id)
puts "Sent: #{status.num_sent}, Failed: #{status.num_failed}"
puts "Status: #{status.status}"

Querying recent pushes

recent = Parse::PushStatus.recent.limit(10).all
recent.each { |s| puts "#{s.status}: #{s.num_sent} sent" }

See Also:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#countInteger

Total number of installations targeted by this push.

Returns:

  • (Integer)

    The target count.



115
# File 'lib/parse/model/classes/push_status.rb', line 115

property :count, :integer

#error_messageString?

Error message if the push failed.

Returns:

  • (String, nil)

    The error message or nil.



130
# File 'lib/parse/model/classes/push_status.rb', line 130

property :error_message

#expiryParse::Date

When the push expires and will no longer be delivered.

Returns:



125
# File 'lib/parse/model/classes/push_status.rb', line 125

property :expiry, :date

#failed_per_typeHash

Breakdown of failed sends by device type.

Returns:

  • (Hash)

    Device type to count mapping.



98
# File 'lib/parse/model/classes/push_status.rb', line 98

property :failed_per_type, :object

#failed_per_utc_offsetHash

Breakdown of failed sends by UTC timezone offset.

Returns:

  • (Hash)

    UTC offset to count mapping.



110
# File 'lib/parse/model/classes/push_status.rb', line 110

property :failed_per_utc_offset, :object

#num_failedInteger

The number of notifications that failed to send.

Returns:

  • (Integer)

    The failure count.



86
# File 'lib/parse/model/classes/push_status.rb', line 86

property :num_failed, :integer

#num_sentInteger

The number of notifications successfully sent.

Returns:

  • (Integer)

    The success count.



81
# File 'lib/parse/model/classes/push_status.rb', line 81

property :num_sent, :integer

#payloadHash

The push payload that was sent.

Returns:

  • (Hash)

    The payload data.



65
# File 'lib/parse/model/classes/push_status.rb', line 65

property :payload, :object

#push_hashString

A unique hash identifying this push notification.

Returns:



55
# File 'lib/parse/model/classes/push_status.rb', line 55

property :push_hash

#push_timeParse::Date

When the push was/will be sent. For scheduled pushes, this is the future time.

Returns:



120
# File 'lib/parse/model/classes/push_status.rb', line 120

property :push_time, :date

#queryHash

The query constraints used to target installations.

Returns:

  • (Hash)

    The query constraint hash.



60
# File 'lib/parse/model/classes/push_status.rb', line 60

property :query, :object

#sent_per_typeHash

Breakdown of successful sends by device type (ios, android, etc.).

Examples:

status.sent_per_type  # => {"ios" => 800, "android" => 450}

Returns:

  • (Hash)

    Device type to count mapping.



93
# File 'lib/parse/model/classes/push_status.rb', line 93

property :sent_per_type, :object

#sent_per_utc_offsetHash

Breakdown of successful sends by UTC timezone offset.

Examples:

status.sent_per_utc_offset  # => {"-8" => 500, "0" => 300, "5" => 200}

Returns:

  • (Hash)

    UTC offset to count mapping.



105
# File 'lib/parse/model/classes/push_status.rb', line 105

property :sent_per_utc_offset, :object

#sourceString

The source of the push ("rest" for API, "webUI" for dashboard).

Returns:

  • (String)

    The push source.



70
# File 'lib/parse/model/classes/push_status.rb', line 70

property :source

#statusString

The current status of the push. One of: "pending", "scheduled", "running", "succeeded", "failed"

Returns:

  • (String)

    The push status.



76
# File 'lib/parse/model/classes/push_status.rb', line 76

property :status

Class Method Details

.failedParse::Query

Query for failed pushes.

Returns:



163
164
165
# File 'lib/parse/model/classes/push_status.rb', line 163

def failed
  query(status: "failed")
end

.pendingParse::Query

Query for pending pushes (not yet started).

Returns:



139
140
141
# File 'lib/parse/model/classes/push_status.rb', line 139

def pending
  query(status: "pending")
end

.recentParse::Query

Query for recent pushes, ordered by creation time descending.

Returns:



169
170
171
# File 'lib/parse/model/classes/push_status.rb', line 169

def recent
  query.order(:created_at.desc)
end

.runningParse::Query

Query for running pushes (currently being sent).

Returns:



151
152
153
# File 'lib/parse/model/classes/push_status.rb', line 151

def running
  query(status: "running")
end

.scheduledParse::Query

Query for scheduled pushes (waiting for push_time).

Returns:



145
146
147
# File 'lib/parse/model/classes/push_status.rb', line 145

def scheduled
  query(status: "scheduled")
end

.succeededParse::Query

Query for succeeded pushes.

Returns:



157
158
159
# File 'lib/parse/model/classes/push_status.rb', line 157

def succeeded
  query(status: "succeeded")
end

Instance Method Details

#complete?Boolean

Check if the push is complete (either succeeded or failed).

Returns:

  • (Boolean)

    true if the push has finished



210
211
212
# File 'lib/parse/model/classes/push_status.rb', line 210

def complete?
  succeeded? || failed?
end

#failed?Boolean

Check if the push failed.

Returns:

  • (Boolean)

    true if status is "failed"



204
205
206
# File 'lib/parse/model/classes/push_status.rb', line 204

def failed?
  status == "failed"
end

#failure_rateFloat

Get the failure rate as a percentage.

Returns:

  • (Float)

    the failure rate (0.0 to 100.0)



242
243
244
# File 'lib/parse/model/classes/push_status.rb', line 242

def failure_rate
  100.0 - success_rate
end

#in_progress?Boolean

Check if the push is still in progress.

Returns:

  • (Boolean)

    true if pending, scheduled, or running



216
217
218
# File 'lib/parse/model/classes/push_status.rb', line 216

def in_progress?
  !complete?
end

#pending?Boolean

Check if the push is pending (not yet started).

Returns:

  • (Boolean)

    true if status is "pending"



180
181
182
# File 'lib/parse/model/classes/push_status.rb', line 180

def pending?
  status == "pending"
end

#running?Boolean

Check if the push is currently running.

Returns:

  • (Boolean)

    true if status is "running"



192
193
194
# File 'lib/parse/model/classes/push_status.rb', line 192

def running?
  status == "running"
end

#scheduled?Boolean

Check if the push is scheduled (waiting for push_time).

Returns:

  • (Boolean)

    true if status is "scheduled"



186
187
188
# File 'lib/parse/model/classes/push_status.rb', line 186

def scheduled?
  status == "scheduled"
end

#succeeded?Boolean

Check if the push succeeded.

Returns:

  • (Boolean)

    true if status is "succeeded"



198
199
200
# File 'lib/parse/model/classes/push_status.rb', line 198

def succeeded?
  status == "succeeded"
end

#success_rateFloat

Get the success rate as a percentage.

Examples:

status.success_rate  # => 98.5

Returns:

  • (Float)

    the success rate (0.0 to 100.0)



234
235
236
237
238
# File 'lib/parse/model/classes/push_status.rb', line 234

def success_rate
  total = total_attempted
  return 0.0 if total == 0
  ((num_sent || 0).to_f / total * 100).round(2)
end

#summaryHash

Get a summary of the push metrics.

Examples:

status.summary
# => { status: "succeeded", sent: 1250, failed: 12, success_rate: 99.05 }

Returns:

  • (Hash)

    summary hash with key metrics



251
252
253
254
255
256
257
258
259
260
261
# File 'lib/parse/model/classes/push_status.rb', line 251

def summary
  {
    status: status,
    sent: num_sent || 0,
    failed: num_failed || 0,
    total_targeted: count || 0,
    success_rate: success_rate,
    sent_per_type: sent_per_type || {},
    failed_per_type: failed_per_type || {},
  }
end

#total_attemptedInteger

Get the total number of notifications attempted (sent + failed).

Returns:

  • (Integer)

    the total count



226
227
228
# File 'lib/parse/model/classes/push_status.rb', line 226

def total_attempted
  (num_sent || 0) + (num_failed || 0)
end