Class: Logical::Naf::ApplicationSchedule
- Inherits:
-
Object
- Object
- Logical::Naf::ApplicationSchedule
show all
- Includes:
- ActionView::Helpers::TextHelper
- Defined in:
- app/models/logical/naf/application_schedule.rb
Constant Summary
collapse
- COLUMNS =
[:id,
:application,
:application_run_group_name,
:application_run_group_restriction_name,
:run_interval_style,
:run_interval,
:application_run_group_quantum,
:application_run_group_limit,
:enqueue_backlogs,
:affinities,
:prerequisites,
:enabled,
:visible]
- ORDER =
Mapping of datatable column positions and job attributes
{ '0' => "id",
'1' => "application_id",
'2' => "application_run_group_name",
'3' => "application_run_group_restriction_id",
'4' => "run_interval_style_id",
'5' => "run_interval",
'6' => "application_run_group_quantum",
'7' => "application_run_group_limit",
'8' => "enqueue_backlogs" }
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of ApplicationSchedule.
34
35
36
|
# File 'app/models/logical/naf/application_schedule.rb', line 34
def initialize(naf_schedule)
@schedule = naf_schedule
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments, &block) ⇒ Object
166
167
168
169
170
171
172
|
# File 'app/models/logical/naf/application_schedule.rb', line 166
def method_missing(method_name, *arguments, &block)
if @schedule.respond_to?(method_name)
@schedule.send(method_name, *arguments, &block)
else
super
end
end
|
Instance Attribute Details
#schedule ⇒ Object
Returns the value of attribute schedule.
5
6
7
|
# File 'app/models/logical/naf/application_schedule.rb', line 5
def schedule
@schedule
end
|
Class Method Details
.search(search) ⇒ Object
38
39
40
41
42
43
44
|
# File 'app/models/logical/naf/application_schedule.rb', line 38
def self.search(search)
direction = search['sSortDir_0']
order = ORDER[search['iSortCol_0']]
::Naf::ApplicationSchedule.
order("#{order} #{direction}").
all.map{ |physical_app_schedule| new(physical_app_schedule) }
end
|
Instance Method Details
#affinities ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'app/models/logical/naf/application_schedule.rb', line 54
def affinities
output = ''
if schedule.try(:application_schedule_affinity_tabs).present?
output = schedule.application_schedule_affinity_tabs.map do |tab|
if tab.affinity_short_name.present?
if tab.affinity_parameter.present? && tab.affinity_parameter > 0
tab.affinity_short_name + "(#{tab.affinity_parameter})"
else
tab.affinity_short_name
end
else
tab.affinity_classification_name + '_' + tab.affinity_name
end
end.join(", \n")
end
return output
end
|
#application_run_group_name ⇒ Object
158
159
160
161
162
163
164
|
# File 'app/models/logical/naf/application_schedule.rb', line 158
def application_run_group_name
if schedule.application_run_group_name.present?
schedule.application_run_group_name
else
'not set'
end
end
|
#display ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'app/models/logical/naf/application_schedule.rb', line 81
def display
output = ''
name = schedule.run_interval_style.name
if name == 'at beginning of day'
output << "daily(#{run_interval})"
elsif name == 'at beginning of hour'
output << "hourly(#{run_interval})"
elsif name == 'after previous run'
output << "run(#{run_interval})"
elsif name == 'keep running'
output << 'always'
end
if schedule.application_run_group_quantum.present?
output << "-#{schedule.application_run_group_quantum}"
else
output << "-1"
end
if schedule.application_run_group_limit.present?
output << "/#{schedule.application_run_group_limit}"
end
output
end
|
#exact_time_of_day(time) ⇒ Object
139
140
141
142
143
144
145
146
147
148
|
# File 'app/models/logical/naf/application_schedule.rb', line 139
def exact_time_of_day(time)
output = ''
minutes = schedule.run_interval % 60
hours = schedule.run_interval / 60
output << hours.to_s + ':'
output << '%02d' % minutes
output = Time.parse(output).strftime('%I:%M %p')
return output
end
|
#help_title ⇒ Object
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
# File 'app/models/logical/naf/application_schedule.rb', line 107
def help_title
output = 'Run this application '
name = schedule.run_interval_style.name
if name == 'at beginning of day'
output << "every day at #{run_interval}. "
elsif name == 'at beginning of hour'
output << "after #{schedule.run_interval} minute(s) of every hour. "
elsif name == 'after previous run'
output << "every #{schedule.run_interval} minute(s). "
elsif name == 'keep running'
output << 'constantly. '
end
output << "This schedule will queue #{schedule.application_run_group_quantum} job(s), and "
output << "will not queue more than the group's limit of #{schedule.application_run_group_limit} job(s)."
output
end
|
#interval_time(time) ⇒ Object
150
151
152
153
154
155
156
|
# File 'app/models/logical/naf/application_schedule.rb', line 150
def interval_time(time)
if time < 9
":0#{time}"
else
":#{time}"
end
end
|
#prerequisites ⇒ Object
73
74
75
76
77
78
79
|
# File 'app/models/logical/naf/application_schedule.rb', line 73
def prerequisites
if schedule.try(:application_schedule_prerequisites).present?
schedule.prerequisites.map do |schedule_prerequisite|
schedule_prerequisite.application.short_name_if_it_exist
end.join(", \n")
end
end
|
#run_interval ⇒ Object
127
128
129
130
131
132
133
134
135
136
137
|
# File 'app/models/logical/naf/application_schedule.rb', line 127
def run_interval
output = ''
time = schedule.run_interval
if schedule.run_interval_style.name == 'at beginning of day'
output = exact_time_of_day(time)
else
output = interval_time(time)
end
output
end
|
#run_interval_style ⇒ Object
50
51
52
|
# File 'app/models/logical/naf/application_schedule.rb', line 50
def run_interval_style
schedule.run_interval_style.name
end
|
#to_hash ⇒ Object
46
47
48
|
# File 'app/models/logical/naf/application_schedule.rb', line 46
def to_hash
Hash[ COLUMNS.map{ |m| [m, send(m)] } ]
end
|