notification_server 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +67 -3
- data/lib/tasks/server.rake +43 -5
- metadata +6 -6
data/README.md
CHANGED
@@ -1,4 +1,68 @@
|
|
1
|
-
ruby
|
2
|
-
|
1
|
+
Notification Server ruby integration
|
2
|
+
====================================
|
3
3
|
|
4
|
-
|
4
|
+

|
5
|
+
|
6
|
+
Ruby integration with nodejs based "notification-server"
|
7
|
+
You can get details information about notification server from
|
8
|
+
[here](http://search.npmjs.org/#/notification-server)
|
9
|
+
|
10
|
+
In brief
|
11
|
+
--------
|
12
|
+
Notification server is an implementation of nowjs based messaging service,
|
13
|
+
Using this you can easily publish messages to all web based subscribers.
|
14
|
+
|
15
|
+
FYI,
|
16
|
+
|
17
|
+
[Nowjs](http://nowjs.com/) is a wrapper around socket.io which has implemented HTML5 Websocket based API, also for fallback it supports wide rage of other choices. (ie. flash socket, json-polling etc..)
|
18
|
+
|
19
|
+
We've built this service so that we could send out live server changes to all running clients
|
20
|
+
(which are built on flash or html5)
|
21
|
+
|
22
|
+
How To Use This Gem ?
|
23
|
+
======================
|
24
|
+
|
25
|
+
Set on Gemfile
|
26
|
+
---------------
|
27
|
+
> gem 'notification_server'
|
28
|
+
|
29
|
+
Generate configuration file
|
30
|
+
---------------------------
|
31
|
+
> rails generate notification_server:config
|
32
|
+
|
33
|
+
This should generate "config/notification_server.yml"
|
34
|
+
|
35
|
+
Run Notification Server
|
36
|
+
-----------------------
|
37
|
+
> rake notification_server:start
|
38
|
+
|
39
|
+
If you want to stop server
|
40
|
+
--------------------------
|
41
|
+
> rake notification_server:stop
|
42
|
+
|
43
|
+
Restart server
|
44
|
+
--------------
|
45
|
+
> rake notification_server:restart
|
46
|
+
|
47
|
+
Integrate notification server nowjs script
|
48
|
+
-------------------------------------------
|
49
|
+
> <%= javascript_include_notification_server %> # This will produce <script src='..../nowjs.js'.../>
|
50
|
+
|
51
|
+
Integrate asynchronously
|
52
|
+
-----------------------
|
53
|
+
> <%= javascript_include_async_notification_server %>
|
54
|
+
|
55
|
+
`Important`: If you use this method remember you can't get "now" variable immediately
|
56
|
+
you have to wait for "now" variable.
|
57
|
+
|
58
|
+
Example Usages
|
59
|
+
---------------
|
60
|
+
> now.receive = function(info, message) { alert(message); }
|
61
|
+
|
62
|
+
> now.register({name: 'hasan'})
|
63
|
+
|
64
|
+
> now.publish('hi')
|
65
|
+
|
66
|
+
> now.publish({data: {tilte: 'abc}})
|
67
|
+
|
68
|
+
- nhm tanveer hossain khan (hasan)
|
data/lib/tasks/server.rake
CHANGED
@@ -2,6 +2,21 @@ require 'fileutils'
|
|
2
2
|
|
3
3
|
module NotificationServer
|
4
4
|
module Tasks
|
5
|
+
class CommandBuilder
|
6
|
+
def initialize
|
7
|
+
@cmds = []
|
8
|
+
end
|
9
|
+
|
10
|
+
def <<(cmd)
|
11
|
+
@cmds << cmd
|
12
|
+
self
|
13
|
+
end
|
14
|
+
|
15
|
+
def build
|
16
|
+
@cmds.flatten.join(' ')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
5
20
|
class Server
|
6
21
|
class << self
|
7
22
|
|
@@ -10,25 +25,48 @@ module NotificationServer
|
|
10
25
|
_argv = []
|
11
26
|
_argv << "-p #{_config['port']}"
|
12
27
|
|
13
|
-
if _config['
|
14
|
-
_argv << "-H #{_config['
|
28
|
+
if _config['hostname'].present?
|
29
|
+
_argv << "-H #{_config['hostname']}"
|
15
30
|
end
|
16
31
|
|
17
32
|
if cmd_exist?
|
18
|
-
|
19
|
-
|
33
|
+
if 'true' == _config['forever'].to_s
|
34
|
+
%w(notification_server.log notification_server_error.log forever.log)
|
35
|
+
.each { |log_file| `touch log/#{log_file}` }
|
36
|
+
|
37
|
+
_cb = CommandBuilder.new
|
38
|
+
_cb << "/usr/bin/env forever -v -a" <<
|
39
|
+
"-o `PWD`/log/notification_server.log" <<
|
40
|
+
"-e `PWD`/log/notification_server_error.log" <<
|
41
|
+
"-l `PWD`/log/forever.log" <<
|
42
|
+
"`which notification-server`" <<
|
43
|
+
_argv
|
44
|
+
_pid = create_pid(spawn(_cb.build), _env)
|
45
|
+
STDOUT.puts "Process id - #{_pid}"
|
46
|
+
else
|
47
|
+
_pid = create_pid(spawn("/usr/bin/env notification-server #{_argv.join(' ')}"), _env)
|
48
|
+
STDOUT.puts "Process id - #{_pid}"
|
49
|
+
end
|
20
50
|
else
|
21
51
|
STDERR.puts "`notification-server` command not found, please install `npm install -g notification-server`"
|
22
52
|
end
|
23
53
|
end
|
24
54
|
|
25
55
|
def stop(_env)
|
56
|
+
_config = config(_env)
|
57
|
+
_forever = 'true' == _config['forever'].to_s
|
58
|
+
|
26
59
|
existing_pid = read_pid(_env)
|
27
|
-
|
60
|
+
|
61
|
+
if !_forever && existing_pid.present?
|
28
62
|
output = `kill #{existing_pid}`
|
29
63
|
STDOUT.puts output
|
30
64
|
STDOUT.puts 'Notification server stopped.'
|
31
65
|
remove_pid(_env)
|
66
|
+
elsif _forever
|
67
|
+
spawn("/usr/bin/env forever stop `which notification-server`")
|
68
|
+
remove_pid(_env)
|
69
|
+
STDOUT.puts 'Notification server stopped.'
|
32
70
|
else
|
33
71
|
STDERR.puts "No such existing notification server process found"
|
34
72
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: notification_server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-05-
|
13
|
+
date: 2012-05-15 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|
17
|
-
requirement: &
|
17
|
+
requirement: &2160951220 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *2160951220
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: jeweler
|
28
|
-
requirement: &
|
28
|
+
requirement: &2160950740 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,7 +33,7 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *2160950740
|
37
37
|
description: Node notification server integration library for ruby project
|
38
38
|
email:
|
39
39
|
- hasan@somewherein.net
|