qm 1.2.1 → 1.2.2
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.
- checksums.yaml +4 -4
- data/README.md +8 -6
- data/lib/defs-mongo.rb +2 -2
- data/lib/qm.rb +4 -4
- data/lib/service.rb +34 -14
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da264638d70859692298a689d2a92d025733719f
|
4
|
+
data.tar.gz: 10ed26e4b45118477d7b48ac2adc611e9e4a3093
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fef5c587e41035dbaa90bb16a1320f3f41b7ab9f306fb454ae5bb662b7ca5f8a5fbd83b275767e58484a9167fafbbf7afd8c727513b96dff3257cda93eefd374
|
7
|
+
data.tar.gz: 3b43abf641787cc89a3730899c1ce44ef665d6b597079190b871d35545f0665ac9f90491f18a029d77fb4a5c0736a43a848a0d08ce4c566ff2bf611b5b0f6fda
|
data/README.md
CHANGED
@@ -1,14 +1,17 @@
|
|
1
|
-
|
1
|
+
qm
|
2
|
+
==
|
3
|
+
|
2
4
|
|
3
5
|
The `qm` gem for [Ruby](http://www.ruby-lang.org/) includes a
|
4
6
|
[QMachine](https://www.qmachine.org) API server and a web server. It uses
|
5
7
|
[MongoDB](http://www.mongodb.org/) for persistent storage, and it can
|
6
8
|
optionally log traffic data into a different MongoDB collection instead of
|
7
|
-
logging to stdout. A client is
|
9
|
+
logging to stdout. A client is also in development.
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
|
11
|
+
Note that the original [SQLite](https://www.sqlite.org/) definitions are now
|
12
|
+
only available in the
|
13
|
+
[`sqlite3` branch](https://github.com/qmachine/qm-ruby/tree/sqlite3). This
|
14
|
+
decision was motivated primarily by the
|
12
15
|
[obstacle it poses](https://devcenter.heroku.com/articles/sqlite3)
|
13
16
|
to deploying on [Heroku](https://www.heroku.com). If you are absolutely in love
|
14
17
|
with SQLite (or just hate MongoDB), consider trying the
|
@@ -21,4 +24,3 @@ For more information, please see the
|
|
21
24
|
|
22
25
|
[](http://badge.fury.io/rb/qm) [](https://gemnasium.com/qmachine/qm-ruby)
|
23
26
|
|
24
|
-
<!-- vim:set syntax=markdown: -->
|
data/lib/defs-mongo.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
#- defs-mongo.rb ~~
|
4
4
|
# ~~ (c) SRW, 16 Jul 2014
|
5
|
-
# ~~ last updated
|
5
|
+
# ~~ last updated 14 Dec 2014
|
6
6
|
|
7
7
|
require 'json'
|
8
8
|
require 'mongo'
|
@@ -99,7 +99,7 @@ module Sinatra
|
|
99
99
|
host: request.host,
|
100
100
|
ip: request.ip,
|
101
101
|
method: request.request_method,
|
102
|
-
|
102
|
+
status_code: response.status,
|
103
103
|
timestamp: Time.now,
|
104
104
|
url: request.fullpath
|
105
105
|
})
|
data/lib/qm.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
#- qm.rb ~~
|
4
4
|
# ~~ (c) SRW, 12 Apr 2013
|
5
|
-
# ~~ last updated
|
5
|
+
# ~~ last updated 07 Dec 2014
|
6
6
|
|
7
7
|
module QM
|
8
8
|
|
@@ -22,7 +22,7 @@ module QM
|
|
22
22
|
configure do
|
23
23
|
convert = lambda do |x|
|
24
24
|
# This converts all keys in a hash to symbols recursively.
|
25
|
-
if
|
25
|
+
if x.is_a?(Hash) then
|
26
26
|
x = x.inject({}) do |memo, (k, v)|
|
27
27
|
memo[k.to_sym] = convert.call(v)
|
28
28
|
memo
|
@@ -32,11 +32,11 @@ module QM
|
|
32
32
|
end
|
33
33
|
options = convert.call(options)
|
34
34
|
set options
|
35
|
-
if
|
35
|
+
if settings.persistent_storage.has_key?(:mongo) then
|
36
36
|
helpers Sinatra::MongoAPIDefs
|
37
37
|
mongo_api_connect
|
38
38
|
end
|
39
|
-
if
|
39
|
+
if settings.trafficlog_storage.has_key?(:mongo) then
|
40
40
|
helpers Sinatra::MongoLogDefs
|
41
41
|
mongo_log_connect
|
42
42
|
after do
|
data/lib/service.rb
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
# of a 'box', 'key', or 'status' value.
|
17
17
|
#
|
18
18
|
# ~~ (c) SRW, 24 Apr 2013
|
19
|
-
# ~~ last updated
|
19
|
+
# ~~ last updated 12 Jan 2015
|
20
20
|
|
21
21
|
require 'sinatra'
|
22
22
|
require 'sinatra/cross_origin'
|
@@ -34,6 +34,7 @@ class QMachineService < Sinatra::Base
|
|
34
34
|
enable_cors: false,
|
35
35
|
enable_web_server: false,
|
36
36
|
hostname: '0.0.0.0',
|
37
|
+
max_body_size: 1048576, # 1024 * 1024 = 1 MB
|
37
38
|
persistent_storage: {},
|
38
39
|
port: 8177,
|
39
40
|
public_folder: 'public',
|
@@ -41,12 +42,15 @@ class QMachineService < Sinatra::Base
|
|
41
42
|
|
42
43
|
# Sinatra mappings and options needed by QMachine.
|
43
44
|
|
44
|
-
mime_type webapp
|
45
|
+
mime_type :webapp, 'application/x-web-app-manifest+json'
|
45
46
|
|
46
47
|
set bind: lambda { settings.hostname },
|
47
48
|
logging: true,
|
49
|
+
raise_errors: false,
|
48
50
|
run: false,
|
49
|
-
|
51
|
+
show_exceptions: false,
|
52
|
+
static: lambda { settings.enable_web_server },
|
53
|
+
x_cascade: false
|
50
54
|
|
51
55
|
# See also: http://www.sinatrarb.com/configuration.html
|
52
56
|
|
@@ -65,9 +69,14 @@ class QMachineService < Sinatra::Base
|
|
65
69
|
# that are loaded at runtime by `QM::launch_service`.
|
66
70
|
|
67
71
|
def hang_up
|
68
|
-
# This helper
|
69
|
-
#
|
70
|
-
|
72
|
+
# This helper literally "hangs up" on the request by immediately
|
73
|
+
# halting further processing, responding with a nondescript 444
|
74
|
+
# status code and an empty body, and then closing the connection.
|
75
|
+
# Unfortunately, closing the connection in this way caused problems
|
76
|
+
# in the Node.js implementation, which suggests that this is not the
|
77
|
+
# correct solution for all concurrency models ... argh.
|
78
|
+
headers = {'Connection' => 'close', 'Content-Type' => 'text/plain'}
|
79
|
+
halt [444, headers, ['']]
|
71
80
|
end
|
72
81
|
|
73
82
|
end
|
@@ -88,8 +97,9 @@ class QMachineService < Sinatra::Base
|
|
88
97
|
hang_up unless (settings.enable_api_server?) and
|
89
98
|
((version == 'box') or (version == 'v1')) and
|
90
99
|
(@box.match(/^[\w\-]+$/)) and
|
91
|
-
((@key.is_a?(String) and @key.match(/^[
|
92
|
-
(@status.is_a?(String) and @status.match(/^[
|
100
|
+
((@key.is_a?(String) and @key.match(/^[\w\-]+$/)) or
|
101
|
+
(@status.is_a?(String) and @status.match(/^[\w\-]+$/))) and
|
102
|
+
(request.content_length.to_s.to_i(10) < settings.max_body_size)
|
93
103
|
cross_origin if settings.enable_cors?
|
94
104
|
end
|
95
105
|
|
@@ -112,12 +122,16 @@ class QMachineService < Sinatra::Base
|
|
112
122
|
# such as when uploading results or submitting new tasks.
|
113
123
|
hang_up unless @key.is_a?(String) and not @status.is_a?(String)
|
114
124
|
body = request.body.read
|
115
|
-
|
125
|
+
begin
|
126
|
+
x = JSON.parse(body)
|
127
|
+
rescue JSON::ParserError
|
128
|
+
hang_up
|
129
|
+
end
|
116
130
|
hang_up unless (@box == x['box']) and (@key == x['key'])
|
117
131
|
if x['status'].is_a?(String) then
|
118
132
|
# This arm runs only when a client writes an avar which represents a
|
119
133
|
# task description.
|
120
|
-
hang_up unless x['status'].match(/^[
|
134
|
+
hang_up unless x['status'].match(/^[\w\-]+$/)
|
121
135
|
set_avar([@box, @key, x['status'], body])
|
122
136
|
else
|
123
137
|
# This arm runs when a client is writing a "regular avar".
|
@@ -127,10 +141,16 @@ class QMachineService < Sinatra::Base
|
|
127
141
|
end
|
128
142
|
|
129
143
|
get '/robots.txt' do
|
130
|
-
# This route
|
131
|
-
#
|
132
|
-
|
133
|
-
|
144
|
+
# This route delegates to the web server, if it was enabled at launch and
|
145
|
+
# if the appropriate file exists; otherwise, it returns a message to web
|
146
|
+
# crawlers instructing them to keep out.
|
147
|
+
robots_file = File.join(settings.public_folder, 'robots.txt')
|
148
|
+
if settings.enable_web_server? then
|
149
|
+
pass if File.exists?(robots_file)
|
150
|
+
y = "User-agent: *\nDisallow: /box/\nDisallow: /v1/\n"
|
151
|
+
else
|
152
|
+
y = "User-agent: *\nDisallow: /\n"
|
153
|
+
end
|
134
154
|
return [200, {'Content-Type' => 'text/plain'}, [y]]
|
135
155
|
end
|
136
156
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean Wilkinson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bson_ext
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - '='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.8.
|
33
|
+
version: 1.8.2
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - '='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.8.
|
40
|
+
version: 1.8.2
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: httparty
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,7 +94,7 @@ dependencies:
|
|
94
94
|
- - '='
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: 0.3.2
|
97
|
-
description:
|
97
|
+
description: Ruby port of QMachine web service + in-progress client
|
98
98
|
email: sean@mathbiol.org
|
99
99
|
executables: []
|
100
100
|
extensions: []
|
@@ -129,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
129
|
version: '0'
|
130
130
|
requirements: []
|
131
131
|
rubyforge_project:
|
132
|
-
rubygems_version: 2.4.
|
132
|
+
rubygems_version: 2.4.5
|
133
133
|
signing_key:
|
134
134
|
specification_version: 4
|
135
135
|
summary: 'QMachine: A platform for World Wide Computing'
|