rails_execution 0.1.5 → 0.1.7

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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +28 -0
  3. data/app/assets/javascripts/executions/base.js +9 -0
  4. data/app/assets/javascripts/executions/flatpickr.min.js +2 -0
  5. data/app/assets/stylesheets/executions/flatpickr.min.css +13 -0
  6. data/app/assets/stylesheets/executions/modify.scss +11 -6
  7. data/app/assets/stylesheets/executions/style.scss +153 -0
  8. data/app/controllers/rails_execution/labels_controller.rb +29 -0
  9. data/app/controllers/rails_execution/tasks_controller.rb +84 -24
  10. data/app/helpers/rails_execution/base_helper.rb +4 -2
  11. data/app/helpers/rails_execution/policy_helper.rb +16 -0
  12. data/app/helpers/rails_execution/rendering_helper.rb +28 -4
  13. data/app/models/rails_execution/label.rb +15 -0
  14. data/app/models/rails_execution/task.rb +71 -3
  15. data/app/models/rails_execution/task_label.rb +6 -0
  16. data/app/services/rails_execution/tasks/create_service.rb +62 -0
  17. data/app/services/rails_execution/tasks/filter_service.rb +49 -0
  18. data/app/views/rails_execution/shared/_paging.html.haml +1 -1
  19. data/app/views/rails_execution/tasks/_actions.html.haml +3 -1
  20. data/app/views/rails_execution/tasks/_activities.html.haml +16 -10
  21. data/app/views/rails_execution/tasks/_advanced_filter.html.haml +115 -0
  22. data/app/views/rails_execution/tasks/_attachment_files.html.haml +2 -11
  23. data/app/views/rails_execution/tasks/_attachments.html.haml +13 -0
  24. data/app/views/rails_execution/tasks/_form.html.haml +50 -14
  25. data/app/views/rails_execution/tasks/_label_collection_select.html.haml +20 -0
  26. data/app/views/rails_execution/tasks/_labels.html.haml +2 -0
  27. data/app/views/rails_execution/tasks/_new_label_modal_form.html.haml +24 -0
  28. data/app/views/rails_execution/tasks/_quick_filter.html.haml +25 -0
  29. data/app/views/rails_execution/tasks/_schedule.html.haml +22 -0
  30. data/app/views/rails_execution/tasks/_task.html.haml +22 -18
  31. data/app/views/rails_execution/tasks/closed.html.haml +2 -1
  32. data/app/views/rails_execution/tasks/completed.html.haml +2 -1
  33. data/app/views/rails_execution/tasks/index.html.haml +2 -1
  34. data/app/views/rails_execution/tasks/show.html.haml +3 -1
  35. data/config/routes.rb +2 -1
  36. data/lib/generators/rails_execution/templates/config.rb.tt +8 -0
  37. data/lib/generators/rails_execution/templates/install.rb.tt +24 -7
  38. data/lib/rails_execution/config.rb +20 -7
  39. data/lib/rails_execution/services/background_execution.rb +56 -0
  40. data/lib/rails_execution/services/create_scheduled_job.rb +61 -0
  41. data/lib/rails_execution/services/remove_scheduled_job.rb +20 -0
  42. data/lib/rails_execution/services/task_scheduler.rb +35 -0
  43. data/lib/rails_execution/version.rb +1 -1
  44. data/lib/rails_execution.rb +4 -0
  45. metadata +21 -2
@@ -0,0 +1,61 @@
1
+ module RailsExecution
2
+ module Services
3
+ class CreateScheduledJob
4
+ NUMBER_OF_MONTHS = 12
5
+
6
+ def initialize(task)
7
+ @task = task
8
+ end
9
+
10
+ def call
11
+ calculate_next_time_at
12
+ create_schedule_job if next_time_at.future?
13
+ end
14
+
15
+ def calculate_next_time_at
16
+ return task.scheduled_at unless task.repeatable?
17
+
18
+ next_time_at = task.scheduled_at
19
+
20
+ if task.repeat_weekdays?
21
+ next_time_at += 1.day until next_time_at.future? && next_time_at.wday.between?(1, 5)
22
+ else
23
+ i = 1
24
+ while next_time_at.past?
25
+ next_time_at = task.scheduled_at + i.public_send(repeat_time_intervals[task.repeat_mode.to_sym])
26
+ i += 1
27
+ end
28
+ end
29
+
30
+ return next_time_at
31
+ end
32
+
33
+ private
34
+
35
+ attr_reader :task
36
+
37
+ def next_time_at
38
+ @next_time_at ||= calculate_next_time_at
39
+ end
40
+
41
+ def repeat_time_intervals
42
+ @repeat_time_intervals ||= {
43
+ hourly: :hours,
44
+ daily: :days,
45
+ weekly: :weeks,
46
+ monthly: :months,
47
+ annually: :years,
48
+ }
49
+ end
50
+
51
+ def create_schedule_job
52
+ jid = ::RailsExecution.configuration.task_scheduler.call(next_time_at, task.id)
53
+ task.update(
54
+ scheduled_at: next_time_at,
55
+ jid: jid.presence
56
+ )
57
+ end
58
+
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,20 @@
1
+ module RailsExecution
2
+ module Services
3
+ class RemoveScheduledJob
4
+
5
+ def initialize(task)
6
+ @task = task
7
+ end
8
+
9
+ def call
10
+ return if task.jid.blank?
11
+
12
+ task.update(jid: nil) if ::RailsExecution.configuration.scheduled_task_remover.call(task.jid)
13
+ end
14
+
15
+ private
16
+
17
+ attr_reader :task
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,35 @@
1
+ module RailsExecution
2
+ module Services
3
+ class TaskScheduler
4
+
5
+ def self.call(task_id)
6
+ self.new(task_id).call
7
+ end
8
+
9
+ def initialize(task_id)
10
+ @task = Task.find(task_id)
11
+ end
12
+
13
+ def call
14
+ task.with_lock do
15
+ next unless task.is_approved? || task.is_processing? && task.scheduled_at.present?
16
+ execute_service = ::RailsExecution::Services::Execution.new(task)
17
+ if execute_service.call
18
+ task.update(status: :completed) unless task.repeatable?
19
+ task.activities.create(owner: task.owner, message: 'Execute: Task completed successfully')
20
+ ::RailsExecution.configuration.notifier.new(task).after_execute_success(task.owner)
21
+ ::RailsExecution::Services::CreateScheduledJob.new(task).call if task.repeatable?
22
+ else
23
+ task.update(status: :failed)
24
+ ::RailsExecution.configuration.notifier.new(task).after_execute_fail(task.owner)
25
+ end
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ attr_reader :task
32
+
33
+ end
34
+ end
35
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsExecution
4
- VERSION = '0.1.5'
4
+ VERSION = '0.1.7'
5
5
  end
@@ -11,8 +11,12 @@ require 'rails_execution/services/paging'
11
11
  require 'rails_execution/services/executor'
12
12
  require 'rails_execution/services/notifier'
13
13
  require 'rails_execution/services/execution'
14
+ require 'rails_execution/services/background_execution'
14
15
  require 'rails_execution/services/approvement'
15
16
  require 'rails_execution/services/syntax_checker'
17
+ require 'rails_execution/services/task_scheduler'
18
+ require 'rails_execution/services/create_scheduled_job'
19
+ require 'rails_execution/services/remove_scheduled_job'
16
20
 
17
21
  module RailsExecution
18
22
 
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.5
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Khoa Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-29 00:00:00.000000000 Z
11
+ date: 2023-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: haml
@@ -52,6 +52,7 @@ files:
52
52
  - app/assets/javascripts/executions/comments.js
53
53
  - app/assets/javascripts/executions/easymde.min.js
54
54
  - app/assets/javascripts/executions/events.js
55
+ - app/assets/javascripts/executions/flatpickr.min.js
55
56
  - app/assets/javascripts/executions/highlight.min.js
56
57
  - app/assets/javascripts/executions/highlight.ruby.min.js
57
58
  - app/assets/javascripts/executions/jquery-3.6.1.min.js
@@ -62,21 +63,28 @@ files:
62
63
  - app/assets/stylesheets/executions/bootstrap-icons.css
63
64
  - app/assets/stylesheets/executions/comments.css
64
65
  - app/assets/stylesheets/executions/easymde.min.css
66
+ - app/assets/stylesheets/executions/flatpickr.min.css
65
67
  - app/assets/stylesheets/executions/fonts.css
66
68
  - app/assets/stylesheets/executions/highlight.min.css
67
69
  - app/assets/stylesheets/executions/modify.scss
68
70
  - app/assets/stylesheets/executions/select2.min.css
71
+ - app/assets/stylesheets/executions/style.scss
69
72
  - app/controllers/rails_execution/base_controller.rb
70
73
  - app/controllers/rails_execution/comments_controller.rb
71
74
  - app/controllers/rails_execution/dashboards_controller.rb
75
+ - app/controllers/rails_execution/labels_controller.rb
72
76
  - app/controllers/rails_execution/tasks_controller.rb
73
77
  - app/helpers/rails_execution/base_helper.rb
74
78
  - app/helpers/rails_execution/policy_helper.rb
75
79
  - app/helpers/rails_execution/rendering_helper.rb
76
80
  - app/models/rails_execution/activity.rb
77
81
  - app/models/rails_execution/comment.rb
82
+ - app/models/rails_execution/label.rb
78
83
  - app/models/rails_execution/task.rb
84
+ - app/models/rails_execution/task_label.rb
79
85
  - app/models/rails_execution/task_review.rb
86
+ - app/services/rails_execution/tasks/create_service.rb
87
+ - app/services/rails_execution/tasks/filter_service.rb
80
88
  - app/views/layouts/execution.html.haml
81
89
  - app/views/rails_execution/comments/_comment.html.haml
82
90
  - app/views/rails_execution/comments/create.js.haml
@@ -89,13 +97,20 @@ files:
89
97
  - app/views/rails_execution/shared/_paging.html.haml
90
98
  - app/views/rails_execution/tasks/_actions.html.haml
91
99
  - app/views/rails_execution/tasks/_activities.html.haml
100
+ - app/views/rails_execution/tasks/_advanced_filter.html.haml
92
101
  - app/views/rails_execution/tasks/_attachment_file_fields.html.haml
93
102
  - app/views/rails_execution/tasks/_attachment_files.html.haml
103
+ - app/views/rails_execution/tasks/_attachments.html.haml
94
104
  - app/views/rails_execution/tasks/_comments.html.haml
95
105
  - app/views/rails_execution/tasks/_form.html.haml
96
106
  - app/views/rails_execution/tasks/_form_scripts.html.haml
107
+ - app/views/rails_execution/tasks/_label_collection_select.html.haml
108
+ - app/views/rails_execution/tasks/_labels.html.haml
97
109
  - app/views/rails_execution/tasks/_new_comment.html.haml
110
+ - app/views/rails_execution/tasks/_new_label_modal_form.html.haml
111
+ - app/views/rails_execution/tasks/_quick_filter.html.haml
98
112
  - app/views/rails_execution/tasks/_reviewers.html.haml
113
+ - app/views/rails_execution/tasks/_schedule.html.haml
99
114
  - app/views/rails_execution/tasks/_script_content.html.haml
100
115
  - app/views/rails_execution/tasks/_show_scripts.html.haml
101
116
  - app/views/rails_execution/tasks/_status.html.haml
@@ -122,11 +137,15 @@ files:
122
137
  - lib/rails_execution/files/reader.rb
123
138
  - lib/rails_execution/files/uploader.rb
124
139
  - lib/rails_execution/services/approvement.rb
140
+ - lib/rails_execution/services/background_execution.rb
141
+ - lib/rails_execution/services/create_scheduled_job.rb
125
142
  - lib/rails_execution/services/execution.rb
126
143
  - lib/rails_execution/services/executor.rb
127
144
  - lib/rails_execution/services/notifier.rb
128
145
  - lib/rails_execution/services/paging.rb
146
+ - lib/rails_execution/services/remove_scheduled_job.rb
129
147
  - lib/rails_execution/services/syntax_checker.rb
148
+ - lib/rails_execution/services/task_scheduler.rb
130
149
  - lib/rails_execution/version.rb
131
150
  homepage: https://github.com/ThanhKhoaIT/rails_execution
132
151
  licenses: