delay_henka 0.3.3 → 0.5.3
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 +5 -5
- data/app/controllers/delay_henka/web/admin/scheduled_actions_controller.rb +26 -0
- data/app/models/delay_henka/scheduled_action.rb +61 -0
- data/app/models/delay_henka/scheduled_change.rb +3 -3
- data/app/views/delay_henka/web/admin/scheduled_actions/_summary_table.html.haml +20 -0
- data/app/views/delay_henka/web/admin/scheduled_actions/index.html.haml +23 -0
- data/app/workers/delay_henka/apply_actions_worker.rb +14 -0
- data/config/routes.rb +1 -0
- data/db/migrate/20190408130947_create_delay_henka_scheduled_actions.rb +15 -0
- data/lib/delay_henka.rb +5 -0
- data/lib/delay_henka/version.rb +1 -1
- metadata +19 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e0c371d4bcae63640c6b5b2689d1340bf14654068a8e7eabd6085889ebd78d99
|
4
|
+
data.tar.gz: 0eada38daa2b68b70349ca3080809cdf590dc03bff10d2468c902dc229db3d23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8f89a6353eb0099c36d97deff1abed8685554b824b4964dbb64c3b85a672b6a3e1978077a9ec49b9f72a6455d0f2fb466633367213393fd3740361a8337753d
|
7
|
+
data.tar.gz: 8b11d1fa0972838bc36f857b8c45f4b8a3e7fe07f633f881faa6542785ed42e88000408a88da65f00af6637daeae9d5c2f80b1c39ea31f993f3010dc89533a6f
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module DelayHenka
|
2
|
+
module Web
|
3
|
+
module Admin
|
4
|
+
class ScheduledActionsController < DelayHenka.base_view_controller.constantize
|
5
|
+
|
6
|
+
before_action :set_scheduled_action, only: %i(destroy)
|
7
|
+
|
8
|
+
def index
|
9
|
+
@actions = ScheduledAction.order('created_at DESC')
|
10
|
+
end
|
11
|
+
|
12
|
+
def destroy
|
13
|
+
@action.destroy!
|
14
|
+
redirect_back fallback_location: web_admin_scheduled_actions_path, flash: { success: 'Destroy succeeded' }
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def set_scheduled_action
|
20
|
+
@action = ScheduledAction.find(params[:id])
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module DelayHenka
|
2
|
+
class ScheduledAction < ApplicationRecord
|
3
|
+
|
4
|
+
STATES = {
|
5
|
+
STAGED: 'staged',
|
6
|
+
COMPLETED: 'completed',
|
7
|
+
ERRORED: 'errored'
|
8
|
+
}
|
9
|
+
|
10
|
+
belongs_to :actionable, polymorphic: true
|
11
|
+
|
12
|
+
validates :submitted_by_id, :schedule_at, presence: true
|
13
|
+
validates :state, inclusion: { in: STATES.values }
|
14
|
+
after_initialize :set_initial_state, if: :new_record?
|
15
|
+
|
16
|
+
scope :staged, -> { where(state: STATES[:STAGED]) }
|
17
|
+
|
18
|
+
def self.schedule(record:, method_name:, argument: nil, by_id:, schedule_at: Time.current)
|
19
|
+
Keka.run do
|
20
|
+
begin
|
21
|
+
arity = record.method(method_name.to_sym).arity
|
22
|
+
Keka.err_unless! (arity == 0 && argument.nil?) || (arity == 1 && !argument.nil?), 'wrong arity'
|
23
|
+
DelayHenka::ScheduledAction.create(
|
24
|
+
actionable: record,
|
25
|
+
method_name: method_name,
|
26
|
+
argument: argument.to_json,
|
27
|
+
submitted_by_id: by_id,
|
28
|
+
schedule_at: schedule_at
|
29
|
+
)
|
30
|
+
rescue NameError => e
|
31
|
+
Keka.err_if! true, e.message
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def apply_action
|
37
|
+
unless actionable
|
38
|
+
# Caution: model validations are bypassed
|
39
|
+
update_columns(state: STATES[:ERRORED], error_message: 'Target record cannot be found')
|
40
|
+
return
|
41
|
+
end
|
42
|
+
|
43
|
+
begin
|
44
|
+
output = actionable.method(method_name.to_sym).arity == 0 ?
|
45
|
+
actionable.send(method_name) :
|
46
|
+
actionable.send(method_name, JSON.parse(argument))
|
47
|
+
update!(state: STATES[:COMPLETED], return_value: output.to_json)
|
48
|
+
rescue => e
|
49
|
+
update!(state: STATES[:ERRORED], error_message: e.message)
|
50
|
+
raise e
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def set_initial_state
|
57
|
+
self.state ||= STATES[:STAGED]
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
@@ -49,12 +49,12 @@ module DelayHenka
|
|
49
49
|
def apply_change
|
50
50
|
if changeable
|
51
51
|
if changeable.update(attribute_name => new_value)
|
52
|
-
update(state: STATES[:COMPLETED])
|
52
|
+
update!(state: STATES[:COMPLETED])
|
53
53
|
else
|
54
|
-
update(state: STATES[:ERRORED], error_message: changeable.errors.full_messages.join(', '))
|
54
|
+
update!(state: STATES[:ERRORED], error_message: changeable.errors.full_messages.join(', '))
|
55
55
|
end
|
56
56
|
else
|
57
|
-
|
57
|
+
update_columns(state: STATES[:ERRORED], error_message: 'Target record cannot be found')
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
-# This partial is rendered by including application.
|
2
|
+
-# Required local variables:
|
3
|
+
-# * scheduled_actions
|
4
|
+
-# To render this partial:
|
5
|
+
-# = render 'delay_henka/web/admin/scheduled_actions/summary_table', scheduled_actions: @actions
|
6
|
+
|
7
|
+
%table.table.table-bordered.table-responsive
|
8
|
+
%thead
|
9
|
+
%tr
|
10
|
+
%th Action
|
11
|
+
%th Arguments
|
12
|
+
%th Schedule At
|
13
|
+
%th Action
|
14
|
+
%tbody
|
15
|
+
- scheduled_actions.each do |action|
|
16
|
+
%tr
|
17
|
+
%td= action.method_name
|
18
|
+
%td= action.argument
|
19
|
+
%td= action.schedule_at
|
20
|
+
%td= link_to 'Delete', delay_henka.web_admin_scheduled_action_path(action), method: :delete
|
@@ -0,0 +1,23 @@
|
|
1
|
+
%h1 Scheduled Actions
|
2
|
+
%table.table
|
3
|
+
%thead
|
4
|
+
%tr
|
5
|
+
%th Type
|
6
|
+
%th Id
|
7
|
+
%th Method
|
8
|
+
%th Argument
|
9
|
+
%th State
|
10
|
+
%th Return Value
|
11
|
+
%th Schedule At
|
12
|
+
%th Submitted By
|
13
|
+
%tbody
|
14
|
+
- @actions.each do |action|
|
15
|
+
%tr
|
16
|
+
%td= action.actionable_type
|
17
|
+
%td= action.actionable_id
|
18
|
+
%td= action.method_name
|
19
|
+
%td= action.argument
|
20
|
+
%td= action.state
|
21
|
+
%td= action.return_value
|
22
|
+
%td= action.schedule_at
|
23
|
+
%td= action.submitted_by_id
|
data/config/routes.rb
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
class CreateDelayHenkaScheduledActions < ActiveRecord::Migration[5.2]
|
2
|
+
def change
|
3
|
+
create_table :delay_henka_scheduled_actions do |t|
|
4
|
+
t.references :actionable, polymorphic: true, null: false, index: { name: 'actionable_index' }
|
5
|
+
t.string :method_name, null: false
|
6
|
+
t.string :state, null: false, index: true
|
7
|
+
t.string :error_message
|
8
|
+
t.integer :submitted_by_id, null: false
|
9
|
+
t.datetime :schedule_at, index: true, null: false
|
10
|
+
t.jsonb :argument
|
11
|
+
t.jsonb :return_value
|
12
|
+
t.timestamps
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/delay_henka.rb
CHANGED
@@ -10,6 +10,11 @@ module DelayHenka
|
|
10
10
|
->{ staged.order('created_at DESC') },
|
11
11
|
class_name: 'DelayHenka::ScheduledChange',
|
12
12
|
as: :changeable
|
13
|
+
|
14
|
+
has_many :upcoming_actions,
|
15
|
+
->{ staged.order('created_at DESC') },
|
16
|
+
class_name: 'DelayHenka::ScheduledAction',
|
17
|
+
as: :actionable
|
13
18
|
end
|
14
19
|
end
|
15
20
|
|
data/lib/delay_henka/version.rb
CHANGED
metadata
CHANGED
@@ -1,57 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: delay_henka
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zino
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '5.2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '5.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: haml
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 5
|
33
|
+
version: '5'
|
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: 5
|
40
|
+
version: '5'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: sidekiq
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 5
|
47
|
+
version: '5'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 5
|
54
|
+
version: '5'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: keka
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,18 +122,24 @@ files:
|
|
122
122
|
- app/assets/javascripts/delay_henka/application.js
|
123
123
|
- app/assets/stylesheets/delay_henka/application.css
|
124
124
|
- app/controllers/delay_henka/application_controller.rb
|
125
|
+
- app/controllers/delay_henka/web/admin/scheduled_actions_controller.rb
|
125
126
|
- app/controllers/delay_henka/web/admin/scheduled_changes_controller.rb
|
126
127
|
- app/helpers/delay_henka/application_helper.rb
|
127
128
|
- app/models/delay_henka/application_record.rb
|
129
|
+
- app/models/delay_henka/scheduled_action.rb
|
128
130
|
- app/models/delay_henka/scheduled_change.rb
|
129
131
|
- app/services/delay_henka/whether_schedule.rb
|
132
|
+
- app/views/delay_henka/web/admin/scheduled_actions/_summary_table.html.haml
|
133
|
+
- app/views/delay_henka/web/admin/scheduled_actions/index.html.haml
|
130
134
|
- app/views/delay_henka/web/admin/scheduled_changes/_summary_table.html.haml
|
131
135
|
- app/views/delay_henka/web/admin/scheduled_changes/index.html.haml
|
132
136
|
- app/views/layouts/delay_henka/application.html.erb
|
137
|
+
- app/workers/delay_henka/apply_actions_worker.rb
|
133
138
|
- app/workers/delay_henka/apply_changes_worker.rb
|
134
139
|
- config/routes.rb
|
135
140
|
- db/migrate/20181228205218_create_delay_henka_scheduled_changes.rb
|
136
141
|
- db/migrate/20190225140848_add_schedule_at.rb
|
142
|
+
- db/migrate/20190408130947_create_delay_henka_scheduled_actions.rb
|
137
143
|
- lib/delay_henka.rb
|
138
144
|
- lib/delay_henka/engine.rb
|
139
145
|
- lib/delay_henka/version.rb
|
@@ -157,8 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
163
|
- !ruby/object:Gem::Version
|
158
164
|
version: '0'
|
159
165
|
requirements: []
|
160
|
-
|
161
|
-
rubygems_version: 2.6.14
|
166
|
+
rubygems_version: 3.0.3
|
162
167
|
signing_key:
|
163
168
|
specification_version: 4
|
164
169
|
summary: Rails engine for scheduled changes
|