Sha256: 7e326e2e025dd2347c2349c9269cecadc25b5819d77911d4d9a71e228bc15c50

Contents?: true

Size: 1.15 KB

Versions: 7

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

require "fileutils"

require "pakyow/support/extension"
require "pakyow/support/serializer"

module Pakyow
  class Application
    module Behavior
      module Realtime
        # Persists the in-memory realtime server across restarts.
        #
        module Serialization
          extend Support::Extension

          apply_extension do
            on "shutdown", priority: :high do
              if Pakyow.config.realtime.adapter == :memory && instance_variable_defined?(:@websocket_server)
                realtime_server_serializer.serialize
              end
            end

            after "boot" do
              if Pakyow.config.realtime.adapter == :memory
                realtime_server_serializer.deserialize
              end
            end
          end

          private def realtime_server_serializer
            Support::Serializer.new(
              @websocket_server.adapter,
              name: "#{config.name}-realtime",
              path: File.join(
                Pakyow.config.root, "tmp", "state"
              ),
              logger: Pakyow.logger
            )
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
pakyow-realtime-1.0.6 lib/pakyow/application/behavior/realtime/serialization.rb
pakyow-realtime-1.0.5 lib/pakyow/application/behavior/realtime/serialization.rb
pakyow-realtime-1.0.4 lib/pakyow/application/behavior/realtime/serialization.rb
pakyow-realtime-1.0.3 lib/pakyow/application/behavior/realtime/serialization.rb
pakyow-realtime-1.0.2 lib/pakyow/application/behavior/realtime/serialization.rb
pakyow-realtime-1.0.1 lib/pakyow/application/behavior/realtime/serialization.rb
pakyow-realtime-1.0.0 lib/pakyow/application/behavior/realtime/serialization.rb