mutx 0.1.27 → 0.1.28
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generators/templates/cron.rb.tt +76 -31
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad86ed628048d56eb4ef9940585112dfb12dccc5
|
4
|
+
data.tar.gz: a99c02d0cb3d6df2aa07aab9436876f936f80560
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e321fff64ce2f200521d4700ce012666cdf2cdf0e44266ecc1b42583f6e115518a41a49958fe6da9d4c0f41c4e48943e5d6433cf6c1aab90359cf5eef345b90a
|
7
|
+
data.tar.gz: 3ef595745a6a6a4fed471329164d1246a546e6fdf871c83b3e4118002756dc3bbd7d65ab8a22dab74949ec8218d6e38ddf2cfe00eaa5c376e7ea59fe8573c314
|
@@ -6,37 +6,82 @@ module Cron
|
|
6
6
|
class Tasks
|
7
7
|
|
8
8
|
def self.cron_jobs
|
9
|
-
|
9
|
+
puts "######### STARTING CRON ##########"
|
10
|
+
@days = [:mo,:tu,:we,:th,:fr,:sa,:su]
|
11
|
+
@today = day_name #name of today
|
12
|
+
|
13
|
+
#BEGIN# Select only cronned tasks that last_exec_time is OK to run
|
14
|
+
cron_tasks = []
|
10
15
|
cron_tasks_list = Mutx::Database::MongoConnector.cron_tasks
|
11
|
-
|
16
|
+
|
17
|
+
puts "#{cron_tasks_list.size} cronned task searched"
|
18
|
+
|
19
|
+
cron_tasks_list.select{|line| cron_tasks << line if (((Time.now.utc - line[:last_exec_time].utc) + 1) >= (line[:cron_time].to_i * 60))}
|
20
|
+
cron_tasks_list = []
|
21
|
+
cron_tasks_list = cron_tasks
|
22
|
+
puts "#{cron_tasks_list.size} cronned task on time to run"
|
23
|
+
#END# Select only cronned tasks that last_exec_time is OK to run
|
12
24
|
|
13
|
-
|
25
|
+
#BEGIN# REMOVING POSSIBLE DUPLICATED TASKS
|
26
|
+
cron_tasks_list_aux = []
|
27
|
+
cron_tasks_list_aux = cron_tasks_list
|
28
|
+
cron_tasks_list = []
|
29
|
+
cron_tasks_list = cron_tasks_list_aux.uniq { |line| [line[:name]].join(":") }
|
14
30
|
|
31
|
+
puts
|
32
|
+
puts "REMOVING DUPLICATED TASKS WITH SAME NAME" if !cron_tasks_list_aux.size.eql? cron_tasks_list.size
|
33
|
+
puts "#{cron_tasks_list.size} cronned task after removing possible duplicated tasks"
|
34
|
+
#END# REMOVING POSSIBLE DUPLICATED TASKS
|
35
|
+
|
36
|
+
#BEGIN#Check if task is running or started
|
37
|
+
cron_tasks = []
|
38
|
+
cron_tasks_list.select{|line| cron_tasks << line if ((Mutx::Database::MongoConnector.running_for_task line[:name]) && (Mutx::Database::MongoConnector.only_started_for_task line[:name]) && (Mutx::Database::MongoConnector.only_running_for_task line[:name])).eql? []}
|
39
|
+
cron_tasks_list = []
|
40
|
+
cron_tasks_list = cron_tasks
|
41
|
+
puts "#{cron_tasks_list.size} cronned task ready to run (not running or started)"
|
42
|
+
#END#Check if task is running or starteda
|
43
|
+
|
44
|
+
# TASK must be right on time to run and unique
|
15
45
|
cron_tasks_list.each do |task|
|
46
|
+
@@now_time = Time.now.hour.to_s+":"+Time.now.min.to_s
|
47
|
+
@@last_exec_time = nil
|
48
|
+
@@last_exec_time = task[:last_exec_time]
|
49
|
+
# Update last_exec_time before to run (because this task is OK to run)
|
50
|
+
Mutx::API::Tasks.cron_update task if (((Time.now.utc - @@last_exec_time.utc) + 1) >= (task[:cron_time].to_i * 60))
|
16
51
|
@none_day = true
|
17
|
-
run = nil
|
18
|
-
started = nil
|
19
|
-
running = nil
|
20
52
|
|
21
|
-
run =
|
22
|
-
started =
|
23
|
-
running =
|
24
|
-
|
25
|
-
|
53
|
+
#run = nil
|
54
|
+
#started = nil
|
55
|
+
#running = nil
|
56
|
+
|
57
|
+
##BEGIN#Check if task is running or started
|
58
|
+
#run = Mutx::Database::MongoConnector.running_for_task task[:name]
|
59
|
+
#started = Mutx::Database::MongoConnector.only_started_for_task task[:name]
|
60
|
+
#running = Mutx::Database::MongoConnector.only_running_for_task task[:name]
|
61
|
+
##END#Check if task is running or started
|
62
|
+
|
63
|
+
#if ((run.empty?) && (started.empty?) && (running.empty?))#RUN task if is not running or started
|
64
|
+
sleep 1
|
26
65
|
validate_and_execute task
|
27
|
-
elsif !started.empty?
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
66
|
+
##elsif ((!started.empty?) || (!running.empty?))
|
67
|
+
#elsif !started.empty? #Started for a long period of time
|
68
|
+
# puts
|
69
|
+
# #puts "Deleting: #{task[:name]} because is started for a long time"
|
70
|
+
# puts "Skipping: #{task[:name]} because is started"
|
71
|
+
# puts
|
72
|
+
# #Mutx::API::Tasks.cron_update task
|
73
|
+
# task = nil
|
74
|
+
# #delete_started started
|
75
|
+
#elsif !running.empty? #If task is running, skip actual task
|
76
|
+
# puts
|
77
|
+
# puts "Skipping: #{task[:name]} because is started"
|
78
|
+
# puts
|
79
|
+
# #Mutx::API::Tasks.cron_update task
|
80
|
+
# task = nil
|
81
|
+
#end
|
38
82
|
end#cron_task
|
39
83
|
Mutx::Database::MongoConnector.force_close
|
84
|
+
puts "######### ENDING CRON ##########"
|
40
85
|
end
|
41
86
|
|
42
87
|
|
@@ -48,7 +93,7 @@ module Cron
|
|
48
93
|
return "th" if num.eql? 4
|
49
94
|
return "fr" if num.eql? 5
|
50
95
|
return "sa" if num.eql? 6
|
51
|
-
return "su" if num.eql?
|
96
|
+
return "su" if num.eql? 0
|
52
97
|
end
|
53
98
|
|
54
99
|
def self.execute task
|
@@ -59,7 +104,7 @@ module Cron
|
|
59
104
|
puts
|
60
105
|
puts "EXECUTING: #{task_name} right now"
|
61
106
|
puts
|
62
|
-
puts Mutx::API::Tasks.cron_update task
|
107
|
+
#puts Mutx::API::Tasks.cron_update task
|
63
108
|
Mutx::API::Execution.start task_name, query_string
|
64
109
|
end
|
65
110
|
|
@@ -87,15 +132,15 @@ module Cron
|
|
87
132
|
@valid = @valid_hours_init + @valid_hours_stop.reverse
|
88
133
|
@valid.pop
|
89
134
|
|
90
|
-
if @valid.include?
|
135
|
+
if @valid.include? @@now_time.match(/(\d*)/)[0].to_i
|
91
136
|
puts
|
92
137
|
puts @valid
|
93
|
-
puts
|
138
|
+
puts @@now_time
|
94
139
|
execute task
|
95
140
|
else
|
96
141
|
puts
|
97
142
|
puts @valid
|
98
|
-
puts "Actual time: #{
|
143
|
+
puts "Actual time: #{@@now_time}"
|
99
144
|
puts "ACTUAL TIME IS OUT OF RANGE FOR: #{task[:name]}"
|
100
145
|
end
|
101
146
|
end
|
@@ -105,16 +150,16 @@ module Cron
|
|
105
150
|
@days.detect{|day| @none_day = "task_with_day" if task[:"#{day}"]}
|
106
151
|
|
107
152
|
# If no day execution is seted, works as always
|
108
|
-
if (((!task[:cron_time].eql? "") && (!task[:cron_time].eql? "0")) && (((Time.now.utc -
|
153
|
+
if (((!task[:cron_time].eql? "") && (!task[:cron_time].eql? "0")) && (((Time.now.utc - @@last_exec_time.utc) + 1) >= (task[:cron_time].to_i * 60)) && (@none_day.eql? true))
|
109
154
|
execute task
|
110
155
|
# If there is a day seted, and that day is today, and no execution time is seted
|
111
|
-
elsif (((!task[:cron_time].eql? "") && (!task[:cron_time].eql? "0")) && (((Time.now.utc -
|
156
|
+
elsif (((!task[:cron_time].eql? "") && (!task[:cron_time].eql? "0")) && (((Time.now.utc - @@last_exec_time.utc) + 1) >= (task[:cron_time].to_i * 60)) && (@none_day.eql? "task_with_day") && (task[:"#{@today}"].eql? "on") && (task[:start_time].empty?) && (task[:stop_time].empty?))
|
112
157
|
execute task
|
113
158
|
# If there is a day seted, and that day is today, and execution range time is seted
|
114
|
-
elsif (((!task[:cron_time].eql? "") && (!task[:cron_time].eql? "0")) && (((Time.now.utc -
|
159
|
+
elsif (((!task[:cron_time].eql? "") && (!task[:cron_time].eql? "0")) && (((Time.now.utc - @@last_exec_time.utc) + 1) >= (task[:cron_time].to_i * 60)) && (@none_day.eql? "task_with_day") && (task[:"#{@today}"].eql? "on") && (task[:start_time]) && (task[:stop_time]) )
|
115
160
|
if task[:start_time] > task[:stop_time] #initial time is greater than stop time
|
116
161
|
check_range_time task
|
117
|
-
elsif (
|
162
|
+
elsif (@@now_time.between? task[:start_time], task[:stop_time]) #stop time is greater than initial time
|
118
163
|
execute task
|
119
164
|
end
|
120
165
|
end#if
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mutx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.28
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roman Rodriguez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-09-
|
11
|
+
date: 2016-09-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|