jobly 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 07003ace15aa4c840ba41208aad221fefa13f8aa420e5cada4e4d0211f82115b
4
- data.tar.gz: c3d7a471c27da897fde7af6974318dc806d9f925524124d5549a3ce89d70bcfe
3
+ metadata.gz: bbc38c3493fa50569ff1b574727a9d854d9c64694d8d7d1ece218ee0e78dd6c4
4
+ data.tar.gz: 518ad55187220df99d35d18b1a9cf9f7e22b0a7eb0455f36dc23c4202b9b7bfa
5
5
  SHA512:
6
- metadata.gz: f1486a30f826453fb836d7fb615466b1d725f672278a522db287a3f16ee466a1f8adc46d039f1d6d1926c8bc9601746097c4cb2617d7864430dd0f605b510d8d
7
- data.tar.gz: 2322d6386a45a024bad898ae693db5bc2048edb2aae418476f73bc3244979096811a4c8f906b135427b0afd3a16139020dd8706e3baa020c776834778a6be68f
6
+ metadata.gz: e2de8768494317847f01b52519bb2cfc374e30e885ba5a1ffa3cf801c5f966c63c2c1c1dbfe74f0a0e1f4614a14051ce86efbd8e8fead41bf44371a2f12b81bd
7
+ data.tar.gz: 9ae8b72be0ae7c4f79ed0616e990d9a58031c16bbe6d19db8236a7f600854fe6f605bcfdd46c1d292f753258c398e7f0bc3a608ea28ee9fe672d10b3dfe3a095
data/README.md CHANGED
@@ -16,8 +16,8 @@ Compact job server with API, CLI, Web UI and a Sidekiq heart.
16
16
  ---
17
17
 
18
18
  <table><tr>
19
- <td width='50%'><a target='_screenshot' href='/demo/terminal.gif'><img src='/demo/terminal.gif'/></a></td>
20
- <td width='50%'><a target='_screenshot' href='/demo/screen.gif'><img src='/demo/screen.gif'/></a></td>
19
+ <td width='50%'><a target='_screenshot' href='/assets/terminal.gif'><img src='/assets/terminal.gif'/></a></td>
20
+ <td width='50%'><a target='_screenshot' href='/assets/screen.gif'><img src='/assets/screen.gif'/></a></td>
21
21
  </tr></table>
22
22
 
23
23
  ---
data/bin/jobly CHANGED
@@ -1,16 +1,18 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'colsole'
3
- require 'jobly'
4
- require 'jobly/boot'
5
-
6
3
  include Colsole
7
4
 
8
- router = Jobly::CLI.router
9
-
10
5
  begin
6
+ require 'jobly'
7
+ require 'jobly/boot'
8
+
9
+ router = Jobly::CLI.router
10
+
11
11
  exit router.run ARGV
12
+
12
13
  rescue => e
13
14
  puts e.backtrace.reverse if ENV['DEBUG']
14
15
  say! "!txtred!#{e.class}: #{e.message}"
16
+ say! "Run with !txtpur!DEBUG=1!txtrst! for backtrace details" unless ENV['DEBUG']
15
17
  exit 1
16
18
  end
@@ -11,4 +11,5 @@ require 'jobly/module_functions'
11
11
  require 'jobly/cli'
12
12
  require 'jobly/job'
13
13
  require 'jobly/jobs'
14
+ require 'jobly/api'
14
15
  require 'jobly/server'
@@ -0,0 +1,79 @@
1
+ require 'jobly'
2
+ require 'sinatra/base'
3
+ require 'sinatra/reloader'
4
+ require 'sinatra/custom_logger'
5
+
6
+ module Jobly
7
+
8
+ class API < Sinatra::Application
9
+ helpers Sinatra::CustomLogger
10
+ using ConvertToTyped
11
+
12
+ configure :development, :production do
13
+ set :server, :puma
14
+ set :logger, Jobly.logger if Jobly.logger
15
+ end
16
+
17
+ configure :development do
18
+ register Sinatra::Reloader
19
+ end
20
+
21
+ before do
22
+ content_type 'application/json'
23
+ end
24
+
25
+ get '/' do
26
+ {
27
+ version: VERSION,
28
+ message: %Q["I'm gonna live till I die" - Frank Sinatra]
29
+ }.to_json
30
+ end
31
+
32
+ get '/*' do
33
+ job = params[:splat].first
34
+ params.delete :splat
35
+ add_job job, params
36
+ end
37
+
38
+ post '/*' do
39
+ job = params[:splat].first
40
+ params.delete :splat
41
+ add_job job, params
42
+ end
43
+
44
+ private
45
+
46
+ def add_job(job, args={})
47
+ job_class = Jobs.get_class job
48
+
49
+ if !job_class
50
+ response = {
51
+ status: 'error',
52
+ message: 'No such job',
53
+ job: job,
54
+ params: args
55
+ }
56
+
57
+ status 404
58
+ logger.debug "[jobly server] No such job (#{job})"
59
+ return response.to_json
60
+ end
61
+
62
+ args = args.convert_to_typed
63
+ if args.empty?
64
+ job_class.perform_async
65
+ else
66
+ job_class.perform_async args
67
+ end
68
+
69
+ response = {
70
+ status: 'received',
71
+ job: job,
72
+ params: args,
73
+ }
74
+
75
+ logger.debug "[jobly server] Job received (#{job})"
76
+ response.to_json
77
+ end
78
+ end
79
+ end
@@ -18,19 +18,30 @@ module Jobly
18
18
  params = args['PARAMS'].to_params
19
19
  url = "#{Jobly.api_url}/#{job}"
20
20
 
21
- response = if params.empty?
22
- HTTP.get url
23
- else
24
- HTTP.get url, params: params
25
- end
21
+ args = [url]
22
+ args << { params: params } unless params.empty?
23
+
24
+ response = client.get *args
26
25
 
27
- if response.code != 200
28
- say "!txtred!#{response.code}"
26
+ raise HTTPError, "#{response.code} #{response.reason}" unless response.status.ok?
27
+
28
+ say "!txtgrn!#{response.code} #{response.reason}"
29
+ lp response.parse
30
+ end
31
+
32
+ private
33
+
34
+ def client
35
+ @client ||= client!
36
+ end
37
+
38
+ def client!
39
+ if Jobly.auth
40
+ user, pass = Jobly.auth.split ':'
41
+ HTTP.basic_auth user: user, pass: pass
29
42
  else
30
- say "!txtgrn!200 OK"
43
+ HTTP
31
44
  end
32
-
33
- lp response.parse
34
45
  end
35
46
 
36
47
  end
@@ -2,9 +2,4 @@ require 'puma'
2
2
  require 'jobly'
3
3
  require 'jobly/boot'
4
4
 
5
- mounts = {
6
- '/' => Sidekiq::Web,
7
- '/do' => Jobly::Server
8
- }
9
-
10
- run Rack::URLMap.new mounts
5
+ run Jobly::Server
@@ -1,4 +1,5 @@
1
1
  module Jobly
2
2
  class Error < StandardError; end
3
3
  class JobNotFound < Error; end
4
+ class HTTPError < Error; end
4
5
  end
@@ -18,6 +18,8 @@ module Jobly
18
18
  status_expiration: ENV['JOBLY_STATUS_EXPIRATION']&.to_i || 30,
19
19
  jobs_namespace: ENV['JOBLY_JOBS_NAMESPACE'],
20
20
  log: ENV['JOBLY_LOG'],
21
+ auth: ENV['JOBLY_AUTH'],
22
+ mounts: nil,
21
23
  }
22
24
  end
23
25
 
@@ -1,79 +1,33 @@
1
1
  require 'jobly'
2
- require 'sinatra/base'
3
- require 'sinatra/reloader'
4
- require 'sinatra/custom_logger'
2
+ require 'rack'
5
3
 
6
4
  module Jobly
7
-
8
- class Server < Sinatra::Application
9
- helpers Sinatra::CustomLogger
10
- using ConvertToTyped
11
-
12
- configure :development, :production do
13
- set :server, :puma
14
- set :logger, Jobly.logger if Jobly.logger
5
+ class Server
6
+ def self.call(env)
7
+ app.call env
15
8
  end
16
9
 
17
- configure :development do
18
- register Sinatra::Reloader
19
- end
20
-
21
- before do
22
- content_type 'application/json'
23
- end
24
-
25
- get '/' do
26
- {
27
- version: VERSION,
28
- message: %Q["I'm gonna live till I die" - Frank Sinatra]
29
- }.to_json
30
- end
10
+ def self.app
11
+ mounts = {
12
+ '/' => Sidekiq::Web,
13
+ '/do' => Jobly::API
14
+ }
15
+ mounts.merge! Jobly.mounts if Jobly.mounts
31
16
 
32
- get '/*' do
33
- job = params[:splat].first
34
- params.delete :splat
35
- add_job job, params
36
- end
17
+ Rack::Builder.new do
18
+ if Jobly.auth
19
+ user, pass = Jobly.auth.split ':'
20
+ use Rack::Auth::Basic, "Jobly" do |username, password|
21
+ username == user && password == pass
22
+ end
23
+ end
37
24
 
38
- post '/*' do
39
- job = params[:splat].first
40
- params.delete :splat
41
- add_job job, params
25
+ run Rack::URLMap.new mounts
26
+ end
42
27
  end
28
+ end
29
+ end
43
30
 
44
- private
45
31
 
46
- def add_job(job, args={})
47
- job_class = Jobs.get_class job
48
32
 
49
- if !job_class
50
- response = {
51
- status: 'error',
52
- message: 'No such job',
53
- job: job,
54
- params: args
55
- }
56
33
 
57
- status 404
58
- logger.debug "[jobly server] No such job (#{job})"
59
- return response.to_json
60
- end
61
-
62
- args = args.convert_to_typed
63
- if args.empty?
64
- job_class.perform_async
65
- else
66
- job_class.perform_async args
67
- end
68
-
69
- response = {
70
- status: 'received',
71
- job: job,
72
- params: args,
73
- }
74
-
75
- logger.debug "[jobly server] Job received (#{job})"
76
- response.to_json
77
- end
78
- end
79
- end
@@ -1,3 +1,3 @@
1
1
  module Jobly
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jobly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-15 00:00:00.000000000 Z
11
+ date: 2019-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mister_bin
@@ -188,6 +188,7 @@ files:
188
188
  - README.md
189
189
  - bin/jobly
190
190
  - lib/jobly.rb
191
+ - lib/jobly/api.rb
191
192
  - lib/jobly/boot.rb
192
193
  - lib/jobly/cli.rb
193
194
  - lib/jobly/commands/base.rb