sinatra-hexacta 0.3.8 → 0.3.9

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: ade8d77e4a11dd25fac0d078c8c80956e6969beaa4cad5745f6f75720d146966
4
- data.tar.gz: dae2ef0fe98be2e088b40dec42901d1d012a077815dc10e64e90fdbecfe53a49
3
+ metadata.gz: '0870be9977d716dfc3ea5c827706e770b716a980fd377ccc8171d745592d43e4'
4
+ data.tar.gz: 5dc71a1b831becbf6203c7febd670f6a28856bb865cc568f2e442b249821509a
5
5
  SHA512:
6
- metadata.gz: dd319e6461b25be1994ed4a2d6a3c1f3b39dfe6a722952ce4b2ac239568f2a56b1cfa2020d181d652da50caf0606fb8da31cec5bb292385aef55b731c5f5c7ef
7
- data.tar.gz: a4a78b99e4763ea4e8f51c1304ea9063ceff8700a01bbabed082452144d87f79558849faa48db62a51e002eac4902c0504a85ef67c3157ea90fb069da431e9da
6
+ metadata.gz: 6076080dfe5163905d5fa63127b06e6b0511ec978a9860753a78219bd3494947a2d94e65e05f73b601f912d2beabbd1631b8ba0a572be47abddde646694b66b6
7
+ data.tar.gz: 5e65ca74bc538b61abac2ea019c6bad442145600ddebc06e2745fec3c2d86f3d8313b3351f1ff86fec82e41d9b5650481b9af327c6d3972747c07d845c56aef3
@@ -6,3 +6,4 @@ require_relative 'mailsender'
6
6
  require_relative 'mail'
7
7
  require_relative 'generalmail'
8
8
  require_relative 'mailbuilder'
9
+ #require_relative 'processmanager'
@@ -0,0 +1,106 @@
1
+ # encoding: utf-8
2
+
3
+ class AsyncProcess
4
+ include SuckerPunch::Job
5
+ attr_reader :handler
6
+ end
7
+
8
+ class ExampleProcess < AsyncProcess
9
+
10
+ attr_reader :log, :error, :interrupted, :name, :id
11
+
12
+ def self.name
13
+ "THE NAME"
14
+ end
15
+
16
+ def perform(handler, other_params)
17
+ @handler = handler
18
+ @handler.total = params[:ids].count
19
+ # loop
20
+ # if error @handler.log("error no falta", e.message)
21
+ # @handler.increase
22
+ #
23
+ end
24
+ end
25
+
26
+ class ProcessHandler
27
+
28
+ attr_reader :log, :error, :interrupted, :name, :id, :performed, :total, :clazz
29
+ attr_accessor :total
30
+
31
+ def initialize(id, name, clazz)
32
+ @id = id
33
+ @total = 0
34
+ @performed = 0
35
+ @log = []
36
+ @error = ""
37
+ @interrupted = false
38
+ @name = name
39
+ @clazz = clazz
40
+ end
41
+
42
+ def progress
43
+ return 0 if @total == 0
44
+ (@performed.to_f / @total.to_f)*100.0
45
+ end
46
+
47
+ def increase
48
+ @performed += 1
49
+ end
50
+
51
+ def log(severity, message)
52
+ @log << "[#{severity}] #{Time.now} #{message}"
53
+ end
54
+
55
+ def interrupt
56
+ @interrupted = true
57
+ end
58
+
59
+ def running?
60
+ @total != @performed
61
+ end
62
+ end
63
+
64
+ class ProcessManager
65
+ include Singleton
66
+
67
+ attr_reader :handlers
68
+
69
+ def initialize
70
+ @handlers = []
71
+ end
72
+
73
+ def find(clazz)
74
+ @handlers.find { |handler| handler.clazz == clazz }
75
+ end
76
+
77
+ def run(*args)
78
+ clean(args.first.to_s)
79
+ if !running?(args.first.to_s)
80
+ handler = ProcessHandler.new(rand(1..100000000), args.first.name, args.first.to_s)
81
+ clazz = args.first
82
+ args[0] = handler
83
+ clazz.perform_async(*args)
84
+ @handlers << handler
85
+ handler
86
+ else
87
+ find(args.first.to_s)
88
+ end
89
+ end
90
+
91
+ def finish(handler)
92
+ @handlers -= [handler]
93
+ end
94
+
95
+ def clean(clazz)
96
+ @handlers.select { |handler| !handler.running? }.each do |handler|
97
+ handler.interrupt
98
+ self.finish(handler)
99
+ end
100
+ end
101
+
102
+ def running?(clazz)
103
+ !@handlers.select { |handler| handler.clazz == clazz }.empty?;
104
+ end
105
+
106
+ end
@@ -2,4 +2,5 @@
2
2
  require_relative 'errors'
3
3
  require_relative 'notifications'
4
4
  require_relative 'params'
5
- require_relative 'reports'
5
+ require_relative 'reports'
6
+ #require_relative 'processes'
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+ module Sinatra
3
+ module ProcessesHandler
4
+ extend Hexacta
5
+
6
+ def enable_processes
7
+ p "Enabling processes..."
8
+
9
+ get '/processes' do
10
+ return "" if ProcessManager.instance.find(params[:class]).nil?
11
+ content_type :json
12
+ return { "progress" => ProcessManager.instance.find(params[:class]).progress }.to_json
13
+ end
14
+
15
+ post '/processes/:id' do |id|
16
+ ProcessManager.instance.interrupt(id)
17
+ end
18
+
19
+ post '/process' do
20
+ a_handler = ProcessManager.instance.run(params)
21
+ a_handler.to_json
22
+ end
23
+ end
24
+
25
+ end
26
+ register ProcessesHandler
27
+ end
28
+
@@ -15,15 +15,15 @@
15
15
  label #{title}
16
16
  .fg-line
17
17
  -if readonly
18
- input.form-control.fg-input id="#{id}" type="#{type}" placeholder="#{placeholder}" name="#{name}" required="" value="#{value}" onkeyup="#{onkeyup}" readonly=''
18
+ input.form-control.fg-input id="#{id}" type="#{type}" placeholder="#{placeholder}" name="#{name}" required="" value="#{value}" class="#{clazz}" onkeyup="#{onkeyup}" readonly=''
19
19
  -else
20
- input.form-control.fg-input id="#{id}" type="#{type}" placeholder="#{placeholder}" name="#{name}" required="" value="#{value}" onkeyup="#{onkeyup}"
20
+ input.form-control.fg-input id="#{id}" type="#{type}" placeholder="#{placeholder}" name="#{name}" required="" value="#{value}" class="#{clazz}" onkeyup="#{onkeyup}"
21
21
 
22
22
  -else
23
23
  .form-group
24
24
  label #{title}
25
25
  .fg-line
26
26
  -if readonly
27
- input.form-control.fg-input id="#{id}" type="#{type}" placeholder="#{placeholder}" name="#{name}" value="#{value}" onkeyup="#{onkeyup}" readonly=''
27
+ input.form-control.fg-input id="#{id}" type="#{type}" placeholder="#{placeholder}" name="#{name}" value="#{value}" onkeyup="#{onkeyup}" class="#{clazz}" readonly=''
28
28
  -else
29
- input.form-control.fg-input id="#{id}" type="#{type}" placeholder="#{placeholder}" name="#{name}" value="#{value}" onkeyup="#{onkeyup}"
29
+ input.form-control.fg-input id="#{id}" type="#{type}" placeholder="#{placeholder}" name="#{name}" value="#{value}" onkeyup="#{onkeyup}" class="#{clazz}"
@@ -14,7 +14,7 @@
14
14
  -if required
15
15
  .form-group.has-success
16
16
  label.fg-label #{placeholder}
17
- select.chosen id="#{id}" name="#{name}[]" data-placeholder=("#{placeholder}") chosen="" multiple="" style=("display: none;") required=""
17
+ select.chosen id="#{id}" class="#{clazz}" name="#{name}[]" data-placeholder=("#{placeholder}") chosen="" multiple="" style=("display: none;") required=""
18
18
  -for element in elements
19
19
  -if selected_elements.include?(element[:value].to_s)
20
20
  option value="#{element[:value]}" selected="" #{element[:text]}
@@ -11,7 +11,7 @@
11
11
  -if required
12
12
  .form-group.has-success
13
13
  label #{placeholder}
14
- select.chosen.form-control id="#{id}" name="#{name}" data-placeholder=("#{placeholder}") style=("display: none;") required=""
14
+ select.chosen.form-control id="#{id}" class="#{clazz}" name="#{name}" data-placeholder=("#{placeholder}") style=("display: none;") required=""
15
15
  -for element in elements
16
16
  -if chosen == element[:value]
17
17
  option value="#{element[:value]}" selected="" #{element[:text]}
@@ -21,7 +21,7 @@
21
21
  -else
22
22
  .form-group
23
23
  label #{placeholder}
24
- select.chosen id="#{id}" name="#{name}" data-placeholder=("#{placeholder}") style=("display: none;")
24
+ select.chosen id="#{id}" class="#{clazz}" name="#{name}" data-placeholder=("#{placeholder}") style=("display: none;")
25
25
  -for element in elements
26
26
  -if chosen == element[:value]
27
27
  option value="#{element[:value]}" selected="" #{element[:text]}
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: 0.3.8
4
+ version: 0.3.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marco Zanger
@@ -67,10 +67,12 @@ files:
67
67
  - lib/sinatra/extensions/mailbuilder.rb
68
68
  - lib/sinatra/extensions/mailsender.rb
69
69
  - lib/sinatra/extensions/notification.rb
70
+ - lib/sinatra/extensions/processmanager.rb
70
71
  - lib/sinatra/handlers/errors.rb
71
72
  - lib/sinatra/handlers/init.rb
72
73
  - lib/sinatra/handlers/notifications.rb
73
74
  - lib/sinatra/handlers/params.rb
75
+ - lib/sinatra/handlers/processes.rb
74
76
  - lib/sinatra/handlers/reports.rb
75
77
  - lib/sinatra/helpers/alerts.rb
76
78
  - lib/sinatra/helpers/cas.rb