Sha256: 8b18cb151329653f73fd2f55722dc67d06488a38d4f1044ee419a221f332af4a

Contents?: true

Size: 1.07 KB

Versions: 3

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

require "fileutils"

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

module Pakyow
  module Realtime
    module Behavior
      # 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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pakyow-realtime-1.0.0.rc5 lib/pakyow/realtime/behavior/serialization.rb
pakyow-realtime-1.0.0.rc4 lib/pakyow/realtime/behavior/serialization.rb
pakyow-realtime-1.0.0.rc3 lib/pakyow/realtime/behavior/serialization.rb