rails_execution 0.1.2 → 0.1.4
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 +4 -4
- data/README.md +65 -0
- data/app/views/rails_execution/tasks/_tips.html.haml +16 -0
- data/lib/rails_execution/files/reader.rb +10 -8
- data/lib/rails_execution/services/executor.rb +25 -0
- data/lib/rails_execution/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e65360fe3eaab3230eb758208801ce69c78593daf6f3c591494706a496760ac
|
4
|
+
data.tar.gz: c349a851be4595c39c925799d3eb0f59cd8ae290e4757ca2af41c621a14b0aa8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8c0041a14acb1d0d905225d864b0c4417c21d18c5986fae3abc8c1b7eabc667f8af5a497e1bed003bfa6849ebef38ef1d709cf2e6bf8267c2eb762cad7ab680
|
7
|
+
data.tar.gz: c7e6ffe4fd22ce9ebd3cb7c38bf1efcff820c458a3c042814f825fd75788848a4bcafb06c129c16060c93e81a71f62cdad79f3b69bbf2accef3637d2cc8f2283
|
data/README.md
CHANGED
@@ -119,3 +119,68 @@ Default value: `20`
|
|
119
119
|
```ruby
|
120
120
|
config.per_page = 10
|
121
121
|
```
|
122
|
+
|
123
|
+
#### Pro-tips
|
124
|
+
##### Logging
|
125
|
+
- In editor, you can call the `log` method with `message` to log the message to logfile
|
126
|
+
|
127
|
+
Example:
|
128
|
+
```ruby
|
129
|
+
log('Read upload file successful')
|
130
|
+
```
|
131
|
+
Output:
|
132
|
+
```
|
133
|
+
==================== Wed, 22 Mar 2023 00:31:48
|
134
|
+
Read upload file successful
|
135
|
+
```
|
136
|
+
|
137
|
+
And within the label liked it
|
138
|
+
```ruby
|
139
|
+
log('Success', 'Read upload file')
|
140
|
+
```
|
141
|
+
Output:
|
142
|
+
```
|
143
|
+
==================== Success
|
144
|
+
Read upload file
|
145
|
+
```
|
146
|
+
|
147
|
+
##### Show object Information
|
148
|
+
|
149
|
+
- If you want to show the object information in loop or in the step by step, you can use the `info` method to show **Model name** and **id**.
|
150
|
+
```ruby
|
151
|
+
ids = [1, 2]
|
152
|
+
Product.where(id: ids).each do |product|
|
153
|
+
info(product)
|
154
|
+
# Your code to process the product
|
155
|
+
end
|
156
|
+
```
|
157
|
+
|
158
|
+
Output:
|
159
|
+
```
|
160
|
+
==================== Product#1
|
161
|
+
==================== Product#2
|
162
|
+
```
|
163
|
+
|
164
|
+
##### Force to stop the process
|
165
|
+
If you want to add the message to log and **STOP** process, you can use the `error!` method
|
166
|
+
|
167
|
+
Example:
|
168
|
+
```ruby
|
169
|
+
error!('Bad-data', 'Unmatched value!') if var_x != var_y
|
170
|
+
```
|
171
|
+
Output:
|
172
|
+
```
|
173
|
+
==================== Bad-data
|
174
|
+
Unmatched value!
|
175
|
+
==================== Rolling back...
|
176
|
+
```
|
177
|
+
OR you can use the `stop!` method to Stop the process
|
178
|
+
|
179
|
+
Example:
|
180
|
+
```ruby
|
181
|
+
stop!
|
182
|
+
```
|
183
|
+
or
|
184
|
+
```ruby
|
185
|
+
stop!('bad-data')
|
186
|
+
```
|
@@ -6,6 +6,22 @@
|
|
6
6
|
Use
|
7
7
|
%code Rails.logger.info 'message...'
|
8
8
|
to add a message into log file
|
9
|
+
%span.tip
|
10
|
+
Use
|
11
|
+
%code info(object)
|
12
|
+
to add a Object info into log file
|
13
|
+
%span.tip
|
14
|
+
Use
|
15
|
+
%code log('Tag', 'message...')
|
16
|
+
to add a message into log file
|
17
|
+
%span.tip
|
18
|
+
Use
|
19
|
+
%code error!('Tag', 'message...')
|
20
|
+
to Stop the execution with the message and Tag in log file
|
21
|
+
%span.tip
|
22
|
+
Use
|
23
|
+
%code stop!('message...')
|
24
|
+
to Stop the execution with the message
|
9
25
|
- if RailsExecution.configuration.file_upload
|
10
26
|
%span.tip
|
11
27
|
Call
|
@@ -33,15 +33,17 @@ module RailsExecution
|
|
33
33
|
attr_reader :task
|
34
34
|
|
35
35
|
def save_to_tempfile(file_name, url)
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
open(url) do |url_file|
|
41
|
-
tmp_file.write(url_file.read)
|
42
|
-
end
|
36
|
+
file = open(url)
|
37
|
+
return file if file.is_a?(Tempfile)
|
38
|
+
|
39
|
+
raise "Unsupported the Filetype #{file.class.name}" unless file.is_a?(StringIO)
|
43
40
|
|
44
|
-
|
41
|
+
file_extension = file.base_uri.path.split('.').last
|
42
|
+
file_extension = ".#{file_extension}" if file_extension
|
43
|
+
tempfile = Tempfile.new([file_name, file_extension])
|
44
|
+
tempfile.binmode
|
45
|
+
tempfile.write(file.string)
|
46
|
+
tempfile
|
45
47
|
end
|
46
48
|
|
47
49
|
end
|
@@ -2,6 +2,8 @@ module RailsExecution
|
|
2
2
|
module Services
|
3
3
|
class Executor
|
4
4
|
|
5
|
+
HIGHLIGHT = '=' * 20
|
6
|
+
|
5
7
|
def initialize(task)
|
6
8
|
@task = task
|
7
9
|
@file_reader = ::RailsExecution.configuration.file_reader.new(task)
|
@@ -19,6 +21,29 @@ module RailsExecution
|
|
19
21
|
@file_reader.get_file(name)
|
20
22
|
end
|
21
23
|
|
24
|
+
def info(object)
|
25
|
+
model_name = object.respond_to?(:model_name) ? object.model_name.name : object.to_s
|
26
|
+
message = model_name + '#' + object&.id.to_s
|
27
|
+
log(message, nil)
|
28
|
+
end
|
29
|
+
|
30
|
+
def log(label = nil, message)
|
31
|
+
label ||= Time.current
|
32
|
+
|
33
|
+
Rails.logger.info("#{HIGHLIGHT} #{label}")
|
34
|
+
Rails.logger.info(message) if message
|
35
|
+
end
|
36
|
+
|
37
|
+
def error!(label = nil, message)
|
38
|
+
log(label, message)
|
39
|
+
stop!
|
40
|
+
end
|
41
|
+
|
42
|
+
def stop!(message = nil)
|
43
|
+
log('Rolling back...', message)
|
44
|
+
raise :rollback
|
45
|
+
end
|
46
|
+
|
22
47
|
end
|
23
48
|
end
|
24
49
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_execution
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Khoa Nguyen
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-03-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: haml
|
@@ -135,7 +135,7 @@ metadata:
|
|
135
135
|
homepage_uri: https://github.com/ThanhKhoaIT/rails_execution
|
136
136
|
source_code_uri: https://github.com/ThanhKhoaIT/rails_execution
|
137
137
|
changelog_uri: https://github.com/ThanhKhoaIT/rails_execution
|
138
|
-
post_install_message:
|
138
|
+
post_install_message:
|
139
139
|
rdoc_options: []
|
140
140
|
require_paths:
|
141
141
|
- lib
|
@@ -150,8 +150,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
150
|
- !ruby/object:Gem::Version
|
151
151
|
version: '0'
|
152
152
|
requirements: []
|
153
|
-
rubygems_version: 3.1.
|
154
|
-
signing_key:
|
153
|
+
rubygems_version: 3.1.6
|
154
|
+
signing_key:
|
155
155
|
specification_version: 4
|
156
156
|
summary: 'Rails Engine: Execute the script for migration, cleanup data and specially
|
157
157
|
case'
|