command_proposal 1.0.2 → 1.0.3

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: 883775b419cb2a8279c8ba335c290a188e5952d535b3a96d4534f38102a7c680
4
- data.tar.gz: d7c8d7cfb062d5863ad5e1c91311f79b295f1445f5a18bc7d643024c45a04944
3
+ metadata.gz: 0fe3241c83226bc2aebbc46b3b8deaec5886dcd6ed8dea95d53e4d84510fb9c5
4
+ data.tar.gz: '09e82ce7d547624f6da07c2536c0c235e4205ff70e76bc8c4e20c07dcbb818da'
5
5
  SHA512:
6
- metadata.gz: 885dff6a34419b84a063d9fad90991a98db1c064938414750b8b556b2ce8313e84ecefefbbb81cea8da460f71e3e24b60d2389cc1e94e7400ac63070f6bbd682
7
- data.tar.gz: 5d105caabf028062646ada81f4d4004102fbdb25d395fd03840be507cf6e4a230e2f65929e85fe8d76942eda2dffb3605941bd8b9a4aef5987d56f8664bdbbc2
6
+ metadata.gz: 57055fced9213819d5d0b9dfbcd3d1d28430a3f34bae8ff6b16b7b48034d68ae71e50411d5d4db90c83502fa7a1bd7ceb02e6861da8f16a558f952d16dbba7d8
7
+ data.tar.gz: 2288b1576b1019d3d1c937d9fa6e346e2facc4b7e58756bed2b6517fb453733c2ec256eda3dec0973c9ffff6ac5331e7b3ff7ee8d8415c241b02543737fe1209
data/README.md CHANGED
@@ -59,7 +59,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
59
59
 
60
60
  ## Contributing
61
61
 
62
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/command_proposal. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/command_proposal/blob/master/CODE_OF_CONDUCT.md).
62
+ Bug reports and pull requests are welcome on GitHub at https://github.com/rockster160/command_proposal. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/rockster160/command_proposal/blob/master/CODE_OF_CONDUCT.md).
63
63
 
64
64
  ## TODO
65
65
 
@@ -74,4 +74,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
74
74
 
75
75
  ## Code of Conduct
76
76
 
77
- Everyone interacting in the CommandProposal project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/command_proposal/blob/master/CODE_OF_CONDUCT.md).
77
+ Everyone interacting in the CommandProposal project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/rockster160/command_proposal/blob/master/CODE_OF_CONDUCT.md).
@@ -7,6 +7,7 @@ module CommandProposal
7
7
  started: "cmd-icon-grey fa fa-clock-o",
8
8
  cancelling: "cmd-icon-yellow fa fa-hourglass-half",
9
9
  cancelled: "cmd-icon-yellow fa fa-stop-circle",
10
+ terminated: "cmd-icon-red fa fa-stop-circle",
10
11
  failed: "cmd-icon-red fa fa-times-circle",
11
12
  success: "cmd-icon-green fa fa-check-circle",
12
13
  }[status&.to_sym] || "cmd-icon-yellow fa fa-question"
@@ -34,6 +34,7 @@ class ::CommandProposal::Iteration < ApplicationRecord
34
34
  cancelling: 4, # Running, but told to stop
35
35
  cancelled: 5,
36
36
  success: 6,
37
+ terminated: 7, # Closed via server restart
37
38
  }
38
39
 
39
40
  delegate :name, to: :task
@@ -52,13 +53,17 @@ class ::CommandProposal::Iteration < ApplicationRecord
52
53
  end
53
54
 
54
55
  def complete?
55
- success? || failed? || cancelled?
56
+ success? || failed? || cancelled? || terminated?
56
57
  end
57
58
 
58
59
  def pending?
59
60
  created?
60
61
  end
61
62
 
63
+ def running?
64
+ started? || cancelling?
65
+ end
66
+
62
67
  def duration
63
68
  return unless started_at?
64
69
 
@@ -1,6 +1,11 @@
1
1
  <%= render partial: "task_detail_table" %>
2
2
 
3
3
  <%= form_for @iteration, url: cmd_path(@iteration), html: { id: "edit-form-1" } do |f| %>
4
+ <% @iteration.brings.each do |bring_module| %>
5
+ <% needs_approval_str = " -- Module needs approval before running Task" unless bring_module.approved? %>
6
+ <%= link_to "Module: #{bring_module.name}#{needs_approval_str}", cmd_path("#{bring_module.friendly_id}") %>
7
+ <br>
8
+ <% end %>
4
9
  <% if @task.approved? && @iteration.params.any? %>
5
10
  <div class="form-field">
6
11
  <% @iteration.params.each do |param_key| %>
@@ -24,7 +29,7 @@
24
29
  <% if current_is_author?(@iteration) %>
25
30
 
26
31
  <% case @iteration.status&.to_sym %>
27
- <% when :created, :failed, :cancelled %>
32
+ <% when :created, :failed, :cancelled, :terminated %>
28
33
  <% unless @iteration.approved_at? %>
29
34
  <% if can_approve?(@iteration) %>
30
35
  <%= f.hidden_field :command, value: :approve %>
@@ -1,4 +1,3 @@
1
- hi
2
1
  <% if @task.iterations.many? %>
3
2
  <table class="cmd-table">
4
3
  <thead>
@@ -2,17 +2,17 @@
2
2
 
3
3
  <% if @iteration.present? %>
4
4
  <%= form_for @iteration, url: cmd_path(@iteration) do |f| %>
5
- <% unless params.key?(:iteration) %>
6
- <% @iteration.brings.each do |bring_module| %>
7
- <% needs_approval_str = " -- Module needs approval before running Task" unless bring_module.approved? %>
8
- <%= link_to "Module: #{bring_module.name}#{needs_approval_str}", cmd_path("#{bring_module.friendly_id}") %>
9
- <br>
10
- <% end %>
5
+ <% @iteration.brings.each do |bring_module| %>
6
+ <% needs_approval_str = " -- Module needs approval before running Task" unless bring_module.approved? %>
7
+ <%= link_to "Module: #{bring_module.name}#{needs_approval_str}", cmd_path("#{bring_module.friendly_id}") %>
8
+ <br>
9
+ <% end %>
11
10
 
11
+ <% unless params.key?(:iteration) %>
12
12
  <% if current_is_author?(@iteration) %>
13
13
 
14
14
  <% case @iteration.status&.to_sym %>
15
- <% when :created, :cancelled %>
15
+ <% when :created, :cancelled, :terminated %>
16
16
  <% if can_approve?(@iteration) %>
17
17
  <%= f.hidden_field :command, value: :approve %>
18
18
  <%= f.submit "Approve!" %>
@@ -9,7 +9,7 @@
9
9
 
10
10
  <%= form_for(@task, url: cmd_path(@task)) do |f| %>
11
11
  <div class="cmd-field">
12
- <%= f.text_field :name, placeholder: "Title", class: "cmd-input" %>
12
+ <%= f.text_field :name, placeholder: "Title", class: "cmd-input", required: true %>
13
13
  </div>
14
14
 
15
15
  <div class="cmd-field">
@@ -77,6 +77,9 @@ module CommandProposal
77
77
  return if @iteration.complete?
78
78
 
79
79
  @iteration.update(status: :cancelling)
80
+ return if ::CommandProposal.sessions.key?("task:#{@task.id}")
81
+
82
+ ::CommandProposal::Services::ShutDown.terminate(@iteration)
80
83
  end
81
84
 
82
85
  def command_close
@@ -4,6 +4,12 @@ module CommandProposal
4
4
  attr_accessor :session
5
5
  # Add expiration and things like that...
6
6
 
7
+ def self.execute(friendly_id)
8
+ task = ::CommandProposal::Task.find_by!(friendly_id: friendly_id)
9
+
10
+ new.execute(task.primary_iteration)
11
+ end
12
+
7
13
  def initialize
8
14
  @session = session
9
15
  end
@@ -20,8 +26,11 @@ module CommandProposal
20
26
  proposal
21
27
  end
22
28
 
23
- def quick_run(iteration)
24
- raise CommandProposal::Error, ":#{iteration.task.friendly_id} does not have approval to run." unless iteration.approved?
29
+ def quick_run(friendly_id)
30
+ task = ::CommandProposal::Task.module.find_by!(friendly_id: friendly_id)
31
+ iteration = task&.primary_iteration
32
+
33
+ raise CommandProposal::Error, ":#{friendly_id} does not have approval to run." unless iteration&.approved?
25
34
 
26
35
  @session.eval(iteration.code)
27
36
  end
@@ -77,7 +86,7 @@ module CommandProposal
77
86
  status = :cancelled
78
87
  end
79
88
 
80
- sleep 1
89
+ sleep 0.4
81
90
  end
82
91
 
83
92
  output = $stdout.try(:string)
@@ -90,7 +99,7 @@ module CommandProposal
90
99
  end
91
100
 
92
101
  def bring_function
93
- "def bring(*func_names); func_names.each { |f| self.quick_run(::CommandProposal::Task.module.find_by!(friendly_id: f).current_iteration) }; end"
102
+ "def bring(*func_names); func_names.each { |f| self.quick_run(f) }; end"
94
103
  end
95
104
 
96
105
  def complete
@@ -0,0 +1,25 @@
1
+ module CommandProposal
2
+ module Services
3
+ module ShutDown
4
+ module_function
5
+
6
+ def reset_all
7
+ pending = ::CommandProposal::Iteration.where(status: [:started, :cancelling])
8
+ pending.find_each do |iteration|
9
+ terminate(iteration)
10
+ end
11
+ end
12
+
13
+ def terminate(iteration)
14
+ return unless iteration.running?
15
+
16
+ terminated_result = iteration.result + "\n\n~~~~~ TERMINATED ~~~~~"
17
+ iteration.update(
18
+ status: :terminated,
19
+ result: terminated_result,
20
+ completed_at: Time.current
21
+ )
22
+ end
23
+ end
24
+ end
25
+ end
@@ -4,5 +4,5 @@
4
4
  # gem push command_proposal-__.gem
5
5
 
6
6
  module CommandProposal
7
- VERSION = '1.0.2'
7
+ VERSION = '1.0.3'
8
8
  end
@@ -2,6 +2,7 @@ require "command_proposal/configuration"
2
2
  require "command_proposal/version"
3
3
  require "command_proposal/engine"
4
4
  require "command_proposal/services/runner"
5
+ require "command_proposal/services/shut_down"
5
6
 
6
7
  module CommandProposal
7
8
  class Error < StandardError; end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: command_proposal
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rocco Nicholls
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-27 00:00:00.000000000 Z
11
+ date: 2021-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -134,6 +134,7 @@ files:
134
134
  - lib/command_proposal/engine.rb
135
135
  - lib/command_proposal/services/command_interpreter.rb
136
136
  - lib/command_proposal/services/runner.rb
137
+ - lib/command_proposal/services/shut_down.rb
137
138
  - lib/command_proposal/version.rb
138
139
  - lib/generators/command_proposal/install/install_generator.rb
139
140
  - lib/generators/command_proposal/install/templates/initializer.rb