sinatra-hexacta 1.0.0 → 1.0.1

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: 235207ce86479d51ab5c1852a286ab92d5b4de8fbd159d584bc79234bcafd5dc
4
- data.tar.gz: 933097a5eca58c05479cb29e93543c9e9ca292eb45c61b940be4ab9c4cf80f9c
3
+ metadata.gz: '028a33ab389fa16403a18c0f0cc8eb21bd0dbdec629ad9aad4ff64edeefae4d4'
4
+ data.tar.gz: 81eaf1d3fd5c9acbfe46bf6e9a46688a36ec6ce55573b76402f3c2716ac1f7d2
5
5
  SHA512:
6
- metadata.gz: c57ec64f35c7f71a043278ffc15e8e131f53cc8a29dfcb353475baa4763a27b09e323eacb16c0f652b209eb44d22383f8e91096403e42e35cfd73f08c5ec10ef
7
- data.tar.gz: 2bfb5b976a50e30124bce1b534953b68e4c95f7398b4d34dace6afee55204b32adaec6bf67ac892f2cd33554a048a4f98be171a0ad17ac72581ef19aa32b8e5e
6
+ metadata.gz: 54f1e6150ddc605f57e5c4fa699f9754924702d8d458c781980f8725324f9c59e7750452fab0f575c615d526a40130f87aa8507a46a16307fb4e8107c1409594
7
+ data.tar.gz: 6c5016a956e3f9c1c376abe8b4578beb10c49044baa0d1b086cd6b0b13bb90e5c3aad7e3bb1f2bbdf405b5ba6687d58b946bc12d49e4543c936f4970dc05a029
@@ -3,6 +3,7 @@
3
3
  class AsyncProcess
4
4
  include SuckerPunch::Job
5
5
  attr_reader :handler
6
+ attr_reader :user_id
6
7
  end
7
8
 
8
9
  class ExampleProcess < AsyncProcess
@@ -25,10 +26,10 @@ end
25
26
 
26
27
  class ProcessHandler
27
28
 
28
- attr_reader :log, :error, :interrupted, :name, :id, :performed, :total, :clazz
29
+ attr_reader :log, :error, :interrupted, :name, :id, :performed, :total, :clazz, :user_id
29
30
  attr_accessor :total
30
31
 
31
- def initialize(id, name, clazz)
32
+ def initialize(id, name, clazz, user_id)
32
33
  @id = id
33
34
  @total = 0
34
35
  @performed = 0
@@ -37,6 +38,7 @@ class ProcessHandler
37
38
  @interrupted = false
38
39
  @name = name
39
40
  @clazz = clazz
41
+ @user_id = user_id
40
42
  end
41
43
 
42
44
  def progress
@@ -74,21 +76,22 @@ class ProcessManager
74
76
  @handlers = []
75
77
  end
76
78
 
77
- def find(clazz)
78
- @handlers.find { |handler| handler.clazz == clazz }
79
+ def find(clazz,user_id)
80
+ @handlers.find { |handler| handler.clazz == clazz && handler.user_id == user_id }
79
81
  end
80
82
 
81
83
  def run(*args)
82
- clean(args.first.to_s)
83
- if !running?(args.first.to_s)
84
- handler = ProcessHandler.new(rand(1..100000000), args.first.name, args.first.to_s)
84
+ user_id = args[1][:user_id]
85
+ clean(args.first.to_s,user_id)
86
+ if !running?(args.first.to_s,user_id)
87
+ handler = ProcessHandler.new(rand(1..100000000), args.first.name, args.first.to_s, user_id)
85
88
  clazz = args.first
86
89
  args[0] = handler
87
90
  clazz.perform_async(*args)
88
91
  @handlers << handler
89
92
  handler
90
93
  else
91
- find(args.first.to_s)
94
+ find(args.first.to_s,user_id)
92
95
  end
93
96
  end
94
97
 
@@ -96,15 +99,15 @@ class ProcessManager
96
99
  @handlers -= [handler]
97
100
  end
98
101
 
99
- def clean(clazz)
100
- @handlers.select { |handler| handler.clazz == clazz }.each do |handler|
102
+ def clean(clazz,user_id)
103
+ @handlers.select { |handler| handler.clazz == clazz && handler.user_id == user_id }.each do |handler|
101
104
  handler.interrupt
102
105
  self.finish(handler)
103
106
  end
104
107
  end
105
108
 
106
- def running?(clazz)
107
- !@handlers.select { |handler| handler.clazz == clazz }.empty?
109
+ def running?(clazz,user_id)
110
+ !@handlers.select { |handler| handler.clazz == clazz && handler.user_id == user_id }.empty?
108
111
  end
109
112
 
110
113
  end
@@ -7,9 +7,10 @@ module Sinatra
7
7
  p "Enabling processes..."
8
8
 
9
9
  get '/processes' do
10
- return "" if ProcessManager.instance.find(params[:class]).nil?
10
+ return "" if ProcessManager.instance.find(params[:class],authenticated(User).id).nil?
11
11
  content_type :json
12
- return { 'name' => ProcessManager.instance.find(params[:class]).name, 'progress' => ProcessManager.instance.find(params[:class]).progress }.to_json
12
+ process = ProcessManager.instance.find(params[:class],authenticated(User).id)
13
+ return { 'name' => process.name, 'progress' => process.progress }.to_json
13
14
  end
14
15
 
15
16
  post '/processes/:clazz' do |clazz|
@@ -18,6 +19,7 @@ module Sinatra
18
19
  end
19
20
 
20
21
  post '/process' do
22
+ params[:user_id] = authenticated(User).id
21
23
  klass = Object.const_get("#{params[:class]}")
22
24
  a_handler = ProcessManager.instance.run(klass,params)
23
25
  a_handler.to_json
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-hexacta
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marco Zanger