Module: Rpush

Defined in:
lib/rpush.rb,
lib/rpush/cli.rb,
lib/rpush/push.rb,
lib/rpush/embed.rb,
lib/rpush/daemon.rb,
lib/rpush/logger.rb,
lib/rpush/plugin.rb,
lib/rpush/version.rb,
lib/rpush/daemon/adm.rb,
lib/rpush/daemon/fcm.rb,
lib/rpush/daemon/rpc.rb,
lib/rpush/daemon/wns.rb,
lib/rpush/daemon/wpns.rb,
lib/rpush/deprecation.rb,
lib/rpush/reflectable.rb,
lib/rpush/daemon/apns2.rb,
lib/rpush/daemon/batch.rb,
lib/rpush/daemon/pushy.rb,
lib/rpush/deprecatable.rb,
lib/rpush/configuration.rb,
lib/rpush/daemon/apnsp8.rb,
lib/rpush/daemon/errors.rb,
lib/rpush/daemon/feeder.rb,
lib/rpush/daemon/webpush.rb,
lib/rpush/daemon/delivery.rb,
lib/rpush/daemon/loggable.rb,
lib/rpush/client/redis/app.rb,
lib/rpush/daemon/constants.rb,
lib/rpush/daemon/app_runner.rb,
lib/rpush/daemon/proc_title.rb,
lib/rpush/daemon/rpc/client.rb,
lib/rpush/daemon/rpc/server.rb,
lib/rpush/multi_json_helper.rb,
lib/rpush/daemon/ring_buffer.rb,
lib/rpush/daemon/store/redis.rb,
lib/rpush/daemon/adm/delivery.rb,
lib/rpush/daemon/apnsp8/token.rb,
lib/rpush/daemon/fcm/delivery.rb,
lib/rpush/daemon/synchronizer.rb,
lib/rpush/daemon/wns/delivery.rb,
lib/rpush/client/redis/adm/app.rb,
lib/rpush/client/redis/fcm/app.rb,
lib/rpush/client/redis/wns/app.rb,
lib/rpush/daemon/queue_payload.rb,
lib/rpush/daemon/wpns/delivery.rb,
lib/rpush/client/redis/apns/app.rb,
lib/rpush/client/redis/wpns/app.rb,
lib/rpush/daemon/apns2/delivery.rb,
lib/rpush/daemon/delivery_error.rb,
lib/rpush/daemon/pushy/delivery.rb,
lib/rpush/daemon/signal_handler.rb,
lib/rpush/daemon/string_helpers.rb,
lib/rpush/reflection_collection.rb,
lib/rpush/client/redis/apns2/app.rb,
lib/rpush/client/redis/pushy/app.rb,
lib/rpush/daemon/apnsp8/delivery.rb,
lib/rpush/daemon/dispatcher/http.rb,
lib/rpush/daemon/dispatcher_loop.rb,
lib/rpush/daemon/retryable_error.rb,
lib/rpush/daemon/store/interface.rb,
lib/rpush/daemon/wns/raw_request.rb,
lib/rpush/client/redis/apnsp8/app.rb,
lib/rpush/daemon/webpush/delivery.rb,
lib/rpush/daemon/wns/post_request.rb,
lib/rpush/client/active_record/app.rb,
lib/rpush/client/redis/webpush/app.rb,
lib/rpush/daemon/wns/badge_request.rb,
lib/rpush/daemon/wns/toast_request.rb,
lib/rpush/client/redis/notification.rb,
lib/rpush/reflection_public_methods.rb,
lib/rpush/client/redis/apns/feedback.rb,
lib/rpush/daemon/interruptible_sleep.rb,
lib/rpush/daemon/retry_header_parser.rb,
lib/rpush/daemon/store/active_record.rb,
lib/rpush/client/active_model/adm/app.rb,
lib/rpush/client/active_model/fcm/app.rb,
lib/rpush/client/active_model/wns/app.rb,
lib/rpush/client/active_model/apns/app.rb,
lib/rpush/client/active_model/wpns/app.rb,
lib/rpush/client/active_record/adm/app.rb,
lib/rpush/client/active_record/fcm/app.rb,
lib/rpush/client/active_record/wns/app.rb,
lib/rpush/daemon/dispatcher/apns_http2.rb,
lib/rpush/client/active_model/apns2/app.rb,
lib/rpush/client/active_model/pushy/app.rb,
lib/rpush/client/active_record/apns/app.rb,
lib/rpush/client/active_record/wpns/app.rb,
lib/rpush/client/redis/adm/notification.rb,
lib/rpush/client/redis/fcm/notification.rb,
lib/rpush/client/redis/wns/notification.rb,
lib/rpush/daemon/service_config_methods.rb,
lib/rpush/client/active_model/apnsp8/app.rb,
lib/rpush/client/active_record/apns2/app.rb,
lib/rpush/client/active_record/pushy/app.rb,
lib/rpush/client/redis/apns/notification.rb,
lib/rpush/client/redis/wpns/notification.rb,
lib/rpush/daemon/dispatcher/apnsp8_http2.rb,
lib/rpush/daemon/google_credential_cache.rb,
lib/rpush/client/active_model/webpush/app.rb,
lib/rpush/client/active_record/apnsp8/app.rb,
lib/rpush/client/redis/apns2/notification.rb,
lib/rpush/client/redis/pushy/notification.rb,
lib/rpush/client/active_model/notification.rb,
lib/rpush/client/active_record/webpush/app.rb,
lib/rpush/client/redis/apnsp8/notification.rb,
lib/rpush/client/active_record/notification.rb,
lib/rpush/client/redis/webpush/notification.rb,
lib/rpush/client/redis/wns/raw_notification.rb,
lib/rpush/client/active_record/apns/feedback.rb,
lib/rpush/client/redis/wns/badge_notification.rb,
lib/rpush/client/active_model/adm/notification.rb,
lib/rpush/client/active_model/fcm/notification.rb,
lib/rpush/client/active_model/wns/notification.rb,
lib/rpush/client/active_model/apns/notification.rb,
lib/rpush/client/active_model/wpns/notification.rb,
lib/rpush/client/active_record/adm/notification.rb,
lib/rpush/client/active_record/fcm/notification.rb,
lib/rpush/client/active_record/wns/notification.rb,
lib/rpush/client/active_model/adm/data_validator.rb,
lib/rpush/client/active_model/apns2/notification.rb,
lib/rpush/client/active_model/pushy/notification.rb,
lib/rpush/client/active_record/apns/notification.rb,
lib/rpush/client/active_record/wpns/notification.rb,
lib/rpush/client/active_model/apnsp8/notification.rb,
lib/rpush/client/active_record/apns2/notification.rb,
lib/rpush/client/active_record/pushy/notification.rb,
lib/rpush/client/active_model/webpush/notification.rb,
lib/rpush/client/active_record/apnsp8/notification.rb,
lib/rpush/daemon/store/active_record/reconnectable.rb,
lib/rpush/client/active_record/webpush/notification.rb,
lib/rpush/client/active_record/wns/raw_notification.rb,
lib/rpush/client/active_record/wns/badge_notification.rb,
lib/rpush/client/active_model/payload_data_size_validator.rb,
lib/rpush/client/active_model/pushy/time_to_live_validator.rb,
lib/rpush/client/active_model/registration_ids_count_validator.rb,
lib/rpush/client/active_model/certificate_private_key_validator.rb,
lib/rpush/client/active_model/apns/device_token_format_validator.rb,
lib/rpush/client/active_model/apns/notification_payload_size_validator.rb,
lib/rpush/client/active_record/apns/active_record_serializable_notification.rb,
lib/rpush/client/active_model/fcm/notification_keys_in_allowed_list_validator.rb,
lib/rpush/client/active_model/fcm/expiry_collapse_key_mutual_inclusion_validator.rb

Defined Under Namespace

Modules: Client, Daemon, Deprecatable, MultiJsonHelper, Reflectable, VERSION Classes: CLI, CertificateExpiredError, Configuration, ConfigurationError, DeliveryError, Deprecation, Logger, Plugin, RateLimitError, ReflectionCollection, RetryableError

Constant Summary collapse

CURRENT_ATTRS =
[:push_poll, :embedded, :pid_file, :batch_size, :push, :client, :logger, :log_file, :foreground, :foreground_logging, :log_level, :plugin]
DEPRECATED_ATTRS =
[]
CONFIG_ATTRS =
CURRENT_ATTRS + DEPRECATED_ATTRS

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configObject



8
9
10
# File 'lib/rpush/configuration.rb', line 8

def config
  @config ||= Rpush::Configuration.new
end

.loggerObject



29
30
31
# File 'lib/rpush.rb', line 29

def self.logger
  @logger ||= Logger.new
end

.reflection_stackObject (readonly)

Returns the value of attribute reflection_stack.



5
6
7
# File 'lib/rpush/reflection_public_methods.rb', line 5

def reflection_stack
  @reflection_stack
end

Class Method Details

.configure {|config| ... } ⇒ Object

Yields:



12
13
14
15
16
# File 'lib/rpush/configuration.rb', line 12

def configure
  return unless block_given?
  yield config
  config.initialize_client
end

.debugObject



38
39
40
# File 'lib/rpush/embed.rb', line 38

def self.debug
  status
end

.embedObject



2
3
4
5
6
7
8
9
10
11
12
13
# File 'lib/rpush/embed.rb', line 2

def self.embed
  require 'rpush/daemon'

  if @embed_thread
    STDERR.puts 'Rpush.embed can only be run once inside this process.'
  end

  Rpush.config.embedded = true
  Rpush.config.foreground = true
  Kernel.at_exit { shutdown }
  @embed_thread = Thread.new { Rpush::Daemon.start }
end

.jruby?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/rpush.rb', line 25

def self.jruby?
  defined? JRUBY_VERSION
end

.plugin(name) ⇒ Object



2
3
4
5
# File 'lib/rpush/plugin.rb', line 2

def self.plugin(name)
  plugins[name] ||= Rpush::Plugin.new(name)
  plugins[name]
end

.pluginsObject



7
8
9
# File 'lib/rpush/plugin.rb', line 7

def self.plugins
  @plugins ||= {}
end

.pushObject



2
3
4
5
6
7
8
9
10
# File 'lib/rpush/push.rb', line 2

def self.push
  require 'rpush/daemon'

  Rpush.config.push = true
  Rpush::Daemon.common_init
  Rpush::Daemon::Synchronizer.sync
  Rpush::Daemon::Feeder.start(true) # non-blocking
  Rpush::Daemon::AppRunner.stop
end

.reflect {|| ... } ⇒ Object

Yields:

  • ()


8
9
10
# File 'lib/rpush/reflection_public_methods.rb', line 8

def self.reflect
  yield reflection_stack[0] if block_given?
end

.rootObject



33
34
35
36
37
38
# File 'lib/rpush.rb', line 33

def self.root
  require 'rails'
  Rails.root || Dir.pwd
rescue LoadError
  Dir.pwd
end

.shutdownObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/rpush/embed.rb', line 15

def self.shutdown
  return unless Rpush.config.embedded
  Rpush::Daemon.shutdown
  @embed_thread.join if @embed_thread
rescue StandardError => e
  STDERR.puts(e.message)
  STDERR.puts(e.backtrace.join("\n"))
ensure
  @embed_thread = nil
end

.statusObject



31
32
33
34
35
36
# File 'lib/rpush/embed.rb', line 31

def self.status
  return unless Rpush.config.embedded
  status = Rpush::Daemon::AppRunner.status
  Rpush.logger.info(JSON.pretty_generate(status))
  status
end

.syncObject



26
27
28
29
# File 'lib/rpush/embed.rb', line 26

def self.sync
  return unless Rpush.config.embedded
  Rpush::Daemon::Synchronizer.sync
end