mutx 0.1.26 → 0.1.27
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 +102 -43
- 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: ecd5479d54587ad777d166a8e0987d6cae8e8a19
|
4
|
+
data.tar.gz: 54ba6417db9d8663cb95644de99d6e5f3633a96b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 063929ac2821e7a3997210805bccb585cd78eda5429650967b4582b1a3231e7a4d4cfcac5217fb6713752236dba3ace33adca080ab5332d782364706e82c17f8
|
7
|
+
data.tar.gz: eebf8e47288ccafb46caf7ca497c53e639ff7ee938e5e19eb9943dbd2bc8f03527dfabb75a8024bdfe90d9c2ac299ed3064f2504446d31413cad9f74c6a48822
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'mutx'
|
2
2
|
require 'chronic'
|
3
|
+
require 'byebug'
|
3
4
|
|
4
5
|
module Cron
|
5
6
|
class Tasks
|
@@ -7,53 +8,34 @@ module Cron
|
|
7
8
|
def self.cron_jobs
|
8
9
|
@days = [:mo,:tu,:we,:th,:fr,:sa,:su]
|
9
10
|
cron_tasks_list = Mutx::Database::MongoConnector.cron_tasks
|
10
|
-
@none_day = true
|
11
11
|
@today = day_name #name of today
|
12
12
|
|
13
13
|
@now_time = Time.now.hour.to_s+":"+Time.now.min.to_s
|
14
14
|
|
15
15
|
cron_tasks_list.each do |task|
|
16
|
-
@
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
puts Mutx::API::Tasks.cron_update task
|
40
|
-
Mutx::API::Execution.start task_name, query_string
|
41
|
-
|
42
|
-
# If there is a day seted, and that day is today, and execution range time is seted
|
43
|
-
elsif (((!task[:cron_time].eql? "") && (!task[:cron_time].eql? "0")) &&
|
44
|
-
(((Time.now.utc - task[:last_exec_time].utc) + 1) >= (task[:cron_time].to_i * 60)) &&
|
45
|
-
(@none_day.eql? "task_with_day") && (task[:"#{@today}"].eql? "on") &&
|
46
|
-
(@now_time.between? task[:start_time], task[:stop_time]))
|
47
|
-
|
48
|
-
query_string = {}
|
49
|
-
query_string = {"execution_name"=>"CRONNED-#{task[:cron_time]}-min"}
|
50
|
-
task_name = task[:name]
|
51
|
-
task_name.gsub!("%20"," ")
|
52
|
-
puts Mutx::API::Tasks.cron_update task
|
53
|
-
Mutx::API::Execution.start task_name, query_string
|
54
|
-
end#if
|
55
|
-
|
56
|
-
end
|
16
|
+
@none_day = true
|
17
|
+
run = nil
|
18
|
+
started = nil
|
19
|
+
running = nil
|
20
|
+
|
21
|
+
run = Mutx::Database::MongoConnector.running_for_task task[:name]
|
22
|
+
started = Mutx::Database::MongoConnector.only_started_for_task task[:name]
|
23
|
+
running = Mutx::Database::MongoConnector.only_running_for_task task[:name]
|
24
|
+
|
25
|
+
if ((run.empty?) && (started.empty?) && (running.empty?))#verify if task is not running or started
|
26
|
+
validate_and_execute task
|
27
|
+
elsif !started.empty?
|
28
|
+
puts
|
29
|
+
puts "Deleting: #{task[:name]} because is started, but not running"
|
30
|
+
puts
|
31
|
+
delete_started started
|
32
|
+
else #task is running
|
33
|
+
puts
|
34
|
+
puts "Task: #{task[:name]} running"
|
35
|
+
puts
|
36
|
+
end
|
37
|
+
|
38
|
+
end#cron_task
|
57
39
|
Mutx::Database::MongoConnector.force_close
|
58
40
|
end
|
59
41
|
|
@@ -68,7 +50,84 @@ module Cron
|
|
68
50
|
return "sa" if num.eql? 6
|
69
51
|
return "su" if num.eql? 7
|
70
52
|
end
|
53
|
+
|
54
|
+
def self.execute task
|
55
|
+
query_string = {}
|
56
|
+
query_string = {"execution_name"=>"CRONNED-#{task[:cron_time]}-min"}
|
57
|
+
task_name = task[:name]
|
58
|
+
task_name.gsub!("%20"," ")
|
59
|
+
puts
|
60
|
+
puts "EXECUTING: #{task_name} right now"
|
61
|
+
puts
|
62
|
+
puts Mutx::API::Tasks.cron_update task
|
63
|
+
Mutx::API::Execution.start task_name, query_string
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.check_range_time task
|
67
|
+
init_hour = task[:start_time].match(/(\d*)/)[0]
|
68
|
+
stop_hour = task[:stop_time].match(/(\d*)/)[0]
|
69
|
+
@valid_hours_init = nil
|
70
|
+
@valid_hours_stop = nil
|
71
|
+
@valid = nil
|
72
|
+
|
73
|
+
@valid_hours_init = [init_hour.to_i]
|
74
|
+
(24-init_hour.to_i).times do
|
75
|
+
if @valid_hours_init.last.eql? 23
|
76
|
+
@valid_hours_init << 00
|
77
|
+
else
|
78
|
+
@valid_hours_init << @valid_hours_init.last + 1
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
@valid_hours_stop = [stop_hour.to_i]
|
83
|
+
(stop_hour.to_i-1).times do
|
84
|
+
@valid_hours_stop << @valid_hours_stop.last - 1
|
85
|
+
end
|
86
|
+
|
87
|
+
@valid = @valid_hours_init + @valid_hours_stop.reverse
|
88
|
+
@valid.pop
|
89
|
+
|
90
|
+
if @valid.include? @now_time.match(/(\d*)/)[0].to_i
|
91
|
+
puts
|
92
|
+
puts @valid
|
93
|
+
puts @now_time
|
94
|
+
execute task
|
95
|
+
else
|
96
|
+
puts
|
97
|
+
puts @valid
|
98
|
+
puts "Actual time: #{@now_time}"
|
99
|
+
puts "ACTUAL TIME IS OUT OF RANGE FOR: #{task[:name]}"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def self.validate_and_execute task
|
104
|
+
|
105
|
+
@days.detect{|day| @none_day = "task_with_day" if task[:"#{day}"]}
|
106
|
+
|
107
|
+
# If no day execution is seted, works as always
|
108
|
+
if (((!task[:cron_time].eql? "") && (!task[:cron_time].eql? "0")) && (((Time.now.utc - task[:last_exec_time].utc) + 1) >= (task[:cron_time].to_i * 60)) && (@none_day.eql? true))
|
109
|
+
execute task
|
110
|
+
# 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 - task[: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
|
+
execute task
|
113
|
+
# 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 - task[: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
|
+
if task[:start_time] > task[:stop_time] #initial time is greater than stop time
|
116
|
+
check_range_time task
|
117
|
+
elsif (@now_time.between? task[:start_time], task[:stop_time]) #stop time is greater than initial time
|
118
|
+
execute task
|
119
|
+
end
|
120
|
+
end#if
|
121
|
+
|
122
|
+
end#validate
|
123
|
+
|
124
|
+
def self.delete_started started_task
|
125
|
+
started_task.each do |task|
|
126
|
+
Mutx::Database::MongoConnector.delete_started_result task["_id"]
|
127
|
+
end
|
128
|
+
end#delete_started
|
129
|
+
|
71
130
|
end#class
|
72
131
|
end#module
|
73
132
|
|
74
|
-
Cron::Tasks.cron_jobs
|
133
|
+
Cron::Tasks.cron_jobs
|
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.27
|
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-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|