Code Monkey home page Code Monkey logo

ruby's Issues

Hardcoded log file

Is there a way to change the path for the log file?

It seems to me that you're creating a new Logger instance by hardcoding it to 'pubnub.log' and it is being save to the root of my project. This will imminently break my code for two reasons:

  1. I'm only tracking the logs falling under /path/to/project/log/*.log, so your log won't be tracked by the logging service I'm using. Also the log won't be rotated as all the other logs from my app.
  2. The permissions for the root folder are different from the log folder and I have some other processes expecting all logs to be readable under another sys user. This is breaking my app every time I deploy a new version and I have to go and change the permissions of the file manually.

All of this points me to the fact that there should be a config setting to select the path where I want the log to be and, optionally, to select the permissions for it.

Let me know if I just missed something in your code that could lead me to fix this issues, or if this capability can be built in the library.

Multi-process access in Heroku environment causes PubNub initialization to occasionally fail

As noted in assaf/uuid#28 and assaf/uuid#6, the UUID gem has multi-process access issues in certain environments (in our case, running push workers in Heroku via Resque or Resque-Pools).

About 2,000 times during a 24-hour period, we see the following crash of the push worker:

Exception: NoMethodError
Error: undefined method `unpack' for nil:NilClass
/app/vendor/bundle/ruby/2.0.0/gems/uuid-2.3.7/lib/uuid.rb:377:in `read_state'
/app/vendor/bundle/ruby/2.0.0/gems/uuid-2.3.7/lib/uuid.rb:333:in `block in next_sequence'
/app/vendor/bundle/ruby/2.0.0/gems/uuid-2.3.7/lib/uuid.rb:367:in `block in open_lock'
/app/vendor/bundle/ruby/2.0.0/gems/uuid-2.3.7/lib/uuid.rb:364:in `open'
/app/vendor/bundle/ruby/2.0.0/gems/uuid-2.3.7/lib/uuid.rb:364:in `open_lock'
/app/vendor/bundle/ruby/2.0.0/gems/uuid-2.3.7/lib/uuid.rb:332:in `next_sequence'
/app/vendor/bundle/ruby/2.0.0/gems/uuid-2.3.7/lib/uuid.rb:263:in `initialize'
/app/vendor/bundle/ruby/2.0.0/bundler/gems/ruby-d159a072b272/lib/pubnub/client.rb:60:in `new'
/app/vendor/bundle/ruby/2.0.0/bundler/gems/ruby-d159a072b272/lib/pubnub/client.rb:60:in `initialize'
/app/vendor/bundle/ruby/2.0.0/bundler/gems/ruby-d159a072b272/lib/pubnub.rb:57:in `new'
/app/vendor/bundle/ruby/2.0.0/bundler/gems/ruby-d159a072b272/lib/pubnub.rb:57:in `new'
/app/app/classes/send_push.rb:50:in `connection'
/app/app/classes/send_push.rb:24:in `call'
/app/app/classes/send_push.rb:15:in `call'
/app/app/workers/push_worker.rb:46:in `perform'
/app/app/workers/push_worker.rb:28:in `perform'

It would be great if the PubNub gem didn't depend on an inheretly-multi-process-unsafe gem for UUID by default (uuidtools seems like a nice alternative, SecureRandom.uuid is a possibility as well).

Retrieve message uuid from ruby api

Hi,

Is there a way to get the message uuid from history through the ruby api? I see javascript api returns message, envelope and channel. I would need the uuid to store the messages locally.

Thanks!

Need a way send custom values to callback in Pubnub.publish()? Also, windowing?

I'm trying to follow Pubnub's best practices for Guaranteed Message Delivery, wherein it gives options on how to graciously handle large messages. The first method was to increase the windowing size, but I haven't seen that option implemented in the Pubnub Ruby API (is this coming?).

In the meantime, I'm chunking my message, sending it in pieces, and reconstructing on the client side, however when I'm chunking my messages a few of the chunks are getting lost - this problem is referenced directly in the best practices, however the solution for this is to not send all the chunks at once - sounds easy enough, but the method described is "waiting for the publish response before sending another message".

Because the structure of the callback message is predefined (somewhere under the hood the callback supplied to the published is getting .call()'ed), I cannot insert any of my own variables into the callback and am only left with the "what happened" status message which includes "sent", "message too large", etc...

I really would like to keep this contained within functions rather than using some global array to store the chunked pieces of the message, so there is a need for a way to pass in some extra variables to the callback function rather than just the status - is this achievable now and I've just overlooked it?

Thanks in advance,

-MM

Publish on multiple channels doesn't work

When I tried to publish a message on multiple channels, then I got:

>> $pubnub.publish(channels: ['user_2', 'user_1'], message: 'Hello') { |m| puts m }
Pubnub::ArgumentError: Pubnub::ArgumentError
        from /Volumes/Document/Projects/xxxx/.gems/gems/pubnub-3.5.3/lib/pubnub/events/publish.rb:23:in `validate!'

When I look at https://github.com/pubnub/ruby/blob/master/lib/pubnub/event.rb#L9, I don't see anywhere that captures value from channels key to process. I tried a quick fix on replacing that line with @channel = options[:channel] || options[:channels], but then it will publish the message only the first channel in the array.

Error on publish "eventmachine not initialized"

I get this error when calling the pubnub.publish method for reasons that are unclear:

Network Error: eventmachine not initialized: evma_connect_to_server

My code looks like such.

PUBNUB = new(
    :publish_key => CONFIG['pubnub']['publish_key'],
    :subscribe_key => CONFIG['pubnub']['subscribe_key'],
    :secret_key => CONFIG['pubnub']['secret_key'],
    :cipher => nil,
    :ssl => false
)

def callback(message)
    if message['occupancy'] <= 0
        return # no clients
    end
    publish_all()
end

def publish_all()
    PUBNUB.publish(
        :channel => 'stacks',
        :message => 'hi',
        :callback => lambda { |message|
            puts message
        }
    )
end

loop do

    # this works...
    #publish_all()
    #sleep 3

    # this doesnt work...
    PUBNUB.here_now(
        :channel => 'stacks',
        :callback => method(:callback)
    )
    sleep 3
end

I'm using ruby 2.0.0 with pubnub (3.3.0.7)

Any help would be swell.

Unsubscribe?

Just wondering. Is there a reason why we don't have an unsubscribe method in the ruby library?

event machine not initialized exception

Backstory

I am implementing the PubNub gem in my Rails app. I use ActiveRecord callbacks as a hook to publish events when a model is created/updated/destroyed/etc. So I've been using the Rails console extensively as I develop to chain together a series of statements that create a variety of model instances, save them and then I monitor the PubNub dev console for my published event (the PubNub dev console is very helpful, btw).

pubnub gem 3.5.1
Rails/Puma

Issue

Sometimes when publishing a message I would get an exception noting that the Event Machine hadn't started.

eventmachine not initialized: evma_install_oneshot_timer

The same set of statements would sometimes result in the exception, sometimes not. Based on some quick research and a bit of conjecture, it seems that the first publish invocation would prompt EM to start, but before it completed initializing, another publish invocation occurs and results in the exception. Like I said, just speculation on my part.

Fix/Workaround

Based on a search of the error message, I came across a fix where as soon as you start EM, have that thread wait until EM is up and running before continuing. I put this in a rails initializer and I haven't had the problem since. Cheers

Thread.new { EM.run } unless EM.reactor_running?
Thread.pass until EM.reactor_running?

Message object does allow values to be arrays

This is in regards to version 3.5.1 of the gem.

Steps to reproduce:

PN = Pubnub.new(:publish_key=>'PUB_KEY',:subscribe_key=>'SUB_KEY')
channel = 'test_channel'
event = 'hey-there'
payload = {
  :channel  => channel,
  :http_sync  => true,
  :callback   => lambda {|envelope| puts envelope }, 
  :message  => {
    :action   => event,
    :data     => nil
  }
}

Verify where value of data object is a string

data = {:key => 'some value'}
payload[:message][:data] = data
PN.publish(payload)
=> valid Pubnub::Response object is returned

Verify where value of data object is a hash

data = {:key => {:sub_key=>'some other value'}}
payload[:message][:data] = data
PN.publish(payload)
=> valid Pubnub::Response object is returned

Throws an error when value of data object is an array

data = {:key => ['value one','value two']}
payload[:message][:data] = data
PN.publish(payload)
=> invalid Pubnub::Response object is returned

<Pubnub::Response:0x007faaf2f870b0 @path=nil, @query=nil, @message="[0, "ERROR SENDING REQUEST AFTER 61 RETRIES"]", @response="[0, "ERROR SENDING REQUEST AFTER 61 RETRIES"]", @timetoken=0>

Let me know if I can provide any other information.

For reference, we only started seeing this behavior after upgrading from version 3.4.1 to 3.5.1

MXing with Ruby

@dsa can you describe your specific use case? Given I know that, I can point you to usage examples with the existing 3.3, or get you pre-release access to the new 3.4.

Thanks,
geremy

Exception inside SubscribeCallback is getting ignored

    local_callback = Pubnub::SubscribeCallback.new(
      message: ->(envelope) {
        request = envelope.result[:data][:message]
        Rails.logger.info("subscribe: RECEIVED MESSAGE - #{request}")
        if request["error"].present?
          raise StandardError.new("failed to process message")
        end
      },
      status: lambda do |envelope|
        if envelope.status[:code] != 200
          Rails.logger.error("subscribe: Pubnub error (#{envelope.status[:category]}): #{envelope.status[:server_response].body.strip}.")
        else
          Rails.logger.info("subscribe: subscribed to #{envelope.status[:subscribed_channels]} with uuid #{envelope.status[:config][:uuid]}")
        end
      end
    )
    pubnub.add_listener(callback: local_callback)
    pubnub.subscribe(
      channels: channels
    )

https://github.com/pubnub/ruby/blob/v4.2.5/lib/pubnub/subscriber.rb#L288

When application raise's an exception inside SubscribeCallback pubnub is silently ignoring it.

presence method does not get a callback on join events

I'm trying out the pubnub Ruby gem with a simple sender, receiver and a presence watcher. The latter is essentially this -

pubnub.presence(
    :channel  => :hello_world,
    :callback => lambda { |message| puts(message.inspect) }
)

The presence watcher launches fine but when i start the sender and receiver to exchange messages across the :hello_world channel, i don't see any join events get logged by the presence watcher.

uninitialized constant Pubnub::Configuration::PUBNUB_VERSION

Just upgraded our Gemfile to point to pubnub-ruby ~> 3.4 and I'm getting this starting rails.

uninitialized constant Pubnub::Configuration::PUBNUB_VERSION
/home/ubuntu/orders/vendor/bundle/ruby/1.9.1/gems/pubnub-ruby-3.4/lib/pubnub/configuration.rb:12:in `<module:Configuration>'
/home/ubuntu/orders/vendor/bundle/ruby/1.9.1/gems/pubnub-ruby-3.4/lib/pubnub/configuration.rb:2:in `<module:Pubnub>'
/home/ubuntu/orders/vendor/bundle/ruby/1.9.1/gems/pubnub-ruby-3.4/lib/pubnub/configuration.rb:1:in `<top (required)>'
/home/ubuntu/orders/vendor/bundle/ruby/1.9.1/gems/pubnub-ruby-3.4/lib/pubnub/client.rb:1:in `<top (required)>'
/home/ubuntu/orders/vendor/bundle/ruby/1.9.1/gems/pubnub-ruby-3.4/lib/pubnub.rb:23:in `<top (required)>'
/home/ubuntu/orders/config/initializers/pubnub.rb:1:in `<top (required)>'
/home/ubuntu/orders/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/engine.rb:588:in `block (2 levels) in <class:Engine>'
/home/ubuntu/orders/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/engine.rb:587:in `each'
/home/ubuntu/orders/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/engine.rb:587:in `block in <class:Engine>'
/home/ubuntu/orders/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `instance_exec'
/home/ubuntu/orders/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `run'
/home/ubuntu/orders/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:55:in `block in run_initializers'
/home/ubuntu/orders/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `each'
/home/ubuntu/orders/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `run_initializers'
/home/ubuntu/orders/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/application.rb:136:in `initialize!'
/home/ubuntu/orders/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/railtie/configurable.rb:30:in `method_missing'
/home/ubuntu/orders/config/environment.rb:3:in `<top (required)>'
/home/ubuntu/orders/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/application.rb:103:in `require_environment!'
/home/ubuntu/orders/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/application.rb:297:in `block (2 levels) in initialize_tasks'
/home/ubuntu/orders/vendor/bundle/ruby/1.9.1/gems/rake-0.9.6/lib/rake/task.rb:228:in `call'
/home/ubuntu/orders/vendor/bundle/ruby/1.9.1/gems/rake-0.9.6/lib/rake/task.rb:228:in `block in execute'
/home/ubuntu/orders/vendor/bundle/ruby/1.9.1/gems/rake-0.9.6/lib/rake/task.rb:223:in `each'
/home/ubuntu/orders/vendor/bundle/ruby/1.9.1/gems/rake-0.9.6/lib/rake/task.rb:223:in `execute'
/home/ubuntu/orders/vendor/bundle/ruby/1.9.1/gems/rake-0.9.6/lib/rake/task.rb:166:in `block in invoke_with_call_chain'
/home/ubuntu/.rvm/rubies/ruby-1.9.3-p374/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/home/ubuntu/orders/vendor/bundle/ruby/1.9.1/gems/rake-0.9.6/lib/rake/task.rb:159:in `invoke_with_call_chain'
/home/ubuntu/orders/vendor/bundle/ruby/1.9.1/gems/rake-0.9.6/lib/rake/task.rb:187:in `block in invoke_prerequisites'
/home/ubuntu/orders/vendor/bundle/ruby/1.9.1/gems/rake-0.9.6/lib/rake/task.rb:185:in `each'
/home/ubuntu/orders/vendor/bundle/ruby/1.9.1/gems/rake-0.9.6/lib/rake/task.rb:185:in `invoke_prerequisites'
/home/ubuntu/orders/vendor/bundle/ruby/1.9.1/gems/rake-0.9.6/lib/rake/task.rb:165:in `block in invoke_with_call_chain'
/home/ubuntu/.rvm/rubies/ruby-1.9.3-p374/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/home/ubuntu/orders/vendor/bundle/ruby/1.9.1/gems/rake-0.9.6/lib/rake/task.rb:159:in `invoke_with_call_chain'
/home/ubuntu/orders/vendor/bundle/ruby/1.9.1/gems/rake-0.9.6/lib/rake/task.rb:152:in `invoke'
/home/ubuntu/orders/vendor/bundle/ruby/1.9.1/gems/rake-0.9.6/lib/rake/application.rb:143:in `invoke_task'
/home/ubuntu/orders/vendor/bundle/ruby/1.9.1/gems/rake-0.9.6/lib/rake/application.rb:101:in `block (2 levels) in top_level'
/home/ubuntu/orders/vendor/bundle/ruby/1.9.1/gems/rake-0.9.6/lib/rake/application.rb:101:in `each'
/home/ubuntu/orders/vendor/bundle/ruby/1.9.1/gems/rake-0.9.6/lib/rake/application.rb:101:in `block in top_level'
/home/ubuntu/orders/vendor/bundle/ruby/1.9.1/gems/rake-0.9.6/lib/rake/application.rb:110:in `run_with_threads'
/home/ubuntu/orders/vendor/bundle/ruby/1.9.1/gems/rake-0.9.6/lib/rake/application.rb:95:in `top_level'
/home/ubuntu/orders/vendor/bundle/ruby/1.9.1/gems/rake-0.9.6/lib/rake/application.rb:73:in `block in run'
/home/ubuntu/orders/vendor/bundle/ruby/1.9.1/gems/rake-0.9.6/lib/rake/application.rb:160:in `standard_exception_handling'
/home/ubuntu/orders/vendor/bundle/ruby/1.9.1/gems/rake-0.9.6/lib/rake/application.rb:70:in `run'
/home/ubuntu/orders/vendor/bundle/ruby/1.9.1/gems/rake-0.9.6/bin/rake:37:in `<top (required)>'
/home/ubuntu/orders/vendor/bundle/ruby/1.9.1/bin/rake:23:in `load'
/home/ubuntu/orders/vendor/bundle/ruby/1.9.1/bin/rake:23:in `<main>'

Synchronous publish?

Hi,

I need a way to make a synchronous publish() call, so that I can use the PubNub response in my own HTTP response.

I've tried this:

    q = Queue.new
    pn.publish(channel: channel,
               message: message,
               callback: lambda { |response| q << response },
               origin: origin_hostname)
    p q.pop

but pop() immediately raises a deadlock error, since there's only one thread(!?). Any ideas what I can do to block until the publish has finished?
This is with pubnub 3.3.0.7.

Logger invocations should use progname

We use a consolidated logging 'system' so the ability to parse out one lib's messages from another is important to us. And while most of your messages start with Pubnub, not all do. That leaves me without a good way to isolate PubNub messages from others.

The Logger class has an alternate way to pass in the args when logging a message. Please consider invoking the logger methods in the way that includes program name (prognam). Extracting relevant bits from the stdlib docs below:

Signature:

info(progname, &block)

Arguments:

progname
In the block form, this is the progname to use in the log message.
block
Evaluates to the message to log. This is not evaluated unless the logger’s level is sufficient to log the message. This allows you to create potentially expensive logging messages that are only called when the logger is configured to show them.

$logger.debug('Pubnub::Client#start_subscribe | Override')
# could become
$logger.debug('PubNub'){'Pubnub::Client#start_subscribe | Override'}

http://ruby-doc.org/stdlib-2.1.1/libdoc/logger/rdoc/Logger.html#method-i-info

"less than 100ms"

handle sending and receiving data across the world in less than 100ms.

The read me says that it sends and receives data in less than 100ms, but I am very curious how y'all are able to go faster than the speed of light, since round trip time at the speed of light from across the world is 133ms.

Or does "across the world" mean really mean a shorter distance, like from one end of a building to another. Which wouldn't be very impressive.

Publishing message error

Hi,

I have found following errors while publishing to a channel to a ruby client . The channel is being subscribed by iOS as well as Android client. We faced an issue where android client was receiving duplicate messages where as iOS client received only a single message .

We ran test where we subscribed on the channel through Android , iOS as well as console. We noticed that sometimes console received a single message twice or thrice but there was only one message in history . Any idea why this is happening ????
screen shot 2013-08-27 at 7 29 13 pm

Problems with PAM ttl in 3.5.0beta

Docs: http://www.pubnub.com/docs/javascript/api/reference.html#grant

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.