taskloop 0.1.0

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 +7 -0
  2. data/.idea/.gitignore +8 -0
  3. data/.idea/misc.xml +4 -0
  4. data/.idea/modules.xml +8 -0
  5. data/.idea/taskloop.iml +51 -0
  6. data/.idea/vcs.xml +6 -0
  7. data/Gemfile +9 -0
  8. data/Gemfile.lock +36 -0
  9. data/README.md +31 -0
  10. data/Rakefile +4 -0
  11. data/exe/taskloop +16 -0
  12. data/lib/taskloop/command/deploy.rb +136 -0
  13. data/lib/taskloop/command/env.rb +134 -0
  14. data/lib/taskloop/command/init.rb +42 -0
  15. data/lib/taskloop/command/launch.rb +67 -0
  16. data/lib/taskloop/command/list.rb +59 -0
  17. data/lib/taskloop/command/log.rb +104 -0
  18. data/lib/taskloop/command/run.rb +106 -0
  19. data/lib/taskloop/command/shutdown.rb +49 -0
  20. data/lib/taskloop/command/undeploy.rb +46 -0
  21. data/lib/taskloop/command.rb +168 -0
  22. data/lib/taskloop/dsl/dsl.rb +63 -0
  23. data/lib/taskloop/extension/integer_extension.rb +25 -0
  24. data/lib/taskloop/extension/string_extension.rb +18 -0
  25. data/lib/taskloop/rules/after_scope_rule.rb +91 -0
  26. data/lib/taskloop/rules/before_scope_rule.rb +90 -0
  27. data/lib/taskloop/rules/between_scope_rule.rb +130 -0
  28. data/lib/taskloop/rules/date_list_rule.rb +47 -0
  29. data/lib/taskloop/rules/default_rule.rb +19 -0
  30. data/lib/taskloop/rules/interval_rule.rb +26 -0
  31. data/lib/taskloop/rules/loop_rule.rb +25 -0
  32. data/lib/taskloop/rules/rule.rb +34 -0
  33. data/lib/taskloop/rules/scope_rule.rb +22 -0
  34. data/lib/taskloop/rules/specific_rule.rb +64 -0
  35. data/lib/taskloop/rules/time_list_rule.rb +49 -0
  36. data/lib/taskloop/task/task.rb +244 -0
  37. data/lib/taskloop/task/task_data_file.rb +46 -0
  38. data/lib/taskloop/task/task_error.rb +17 -0
  39. data/lib/taskloop/task/task_property.rb +294 -0
  40. data/lib/taskloop/utils/proj_tasklist.rb +145 -0
  41. data/lib/taskloop/version.rb +5 -0
  42. data/lib/taskloop.rb +9 -0
  43. data/sig/taskloop.rbs +4 -0
  44. data/taskloop.gemspec +37 -0
  45. metadata +103 -0
@@ -0,0 +1,90 @@
1
+ module TaskLoop
2
+ class BeforeScopeRule < ScopeRule
3
+
4
+ attr_accessor :right
5
+
6
+ def initialize(unit, scope, right)
7
+ super unit, scope
8
+ @right = right
9
+ end
10
+
11
+ def invalidate!
12
+ super
13
+ if @unit == :day
14
+ unless Task::WEEK.has_key?(@right) || Task::DAY.has_key?(@right)
15
+ raise ArgumentError, "#{@right} must be a Symbol defined in Task::WEEK or Task::DAY"
16
+ end
17
+ return
18
+ end
19
+
20
+ if @unit == :month
21
+ unless Task::MONTH.has_key?(@right)
22
+ raise ArgumentError, "#{@right} must be a Symbol defined in Task::MONTH"
23
+ end
24
+ return
25
+ end
26
+
27
+ unless @right.is_a?(Integer)
28
+ raise TypeError, "'right' need to be Symbol or Integer"
29
+ end
30
+
31
+ if @unit == :minute && (@right < 0 || @right > 59)
32
+ raise ArgumentError, "'right' for 'minute' must >= 0 and <= 59"
33
+ end
34
+
35
+ if @unit == :hour && (@right < 0 || @right > 23)
36
+ raise ArgumentError, "'right' for 'hour' must >= 0 and <= 23"
37
+ end
38
+ end
39
+
40
+ def right_value
41
+ if (Task::DAY.has_key?(@right))
42
+ return Task::DAY[@right]
43
+ end
44
+ if (Task::WEEK.has_key?(@right))
45
+ return Task::WEEK[@right]
46
+ end
47
+ if (Task::MONTH.has_key?(@right))
48
+ return Task::MONTH[@right]
49
+ end
50
+
51
+ unless @right != nil && @right.is_a?(Integer)
52
+ return -1
53
+ end
54
+
55
+ return @right
56
+ end
57
+
58
+ def is_week_value?
59
+ if @unit == :day && Task::WEEK.has_key?(@right)
60
+ return true
61
+ end
62
+ return false
63
+ end
64
+
65
+ def is_conform_rule?(last_exec_time)
66
+ current = Time.now
67
+ value = right_value
68
+ result = false
69
+ case @unit
70
+ when :year then
71
+ result = current.year < value
72
+ when :month then
73
+ result = current.month < value
74
+ when :day then
75
+ if is_week_value?
76
+ result = current.wday < (value % TaskLoop::WEEK_BASE)
77
+ else
78
+ result = current.day < value
79
+ end
80
+ when :hour then
81
+ result = current.hour < value
82
+ end
83
+ return result
84
+ end
85
+
86
+ def desc
87
+ super + " #{right}"
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,130 @@
1
+ module TaskLoop
2
+ class BetweenScopeRule < ScopeRule
3
+
4
+ attr_accessor :left
5
+
6
+ attr_accessor :right
7
+
8
+ def initialize(unit, scope, left, right)
9
+ super unit, scope
10
+ @left = left
11
+ @right = right
12
+ end
13
+
14
+ def invalidate!
15
+ super
16
+ if @unit == :day
17
+ if Task::WEEK.has_key?(@left) && Task::WEEK.has_key?(@right)
18
+ unless Task::WEEK[@left] < Task::WEEK[@right]
19
+ raise ArgumentError, "'left' must less than 'right'"
20
+ end
21
+ return
22
+ end
23
+ if Task::DAY.has_key?(@left) && Task::DAY.has_key?(@right)
24
+ unless Task::WEEK[@left] < Task::WEEK[@right]
25
+ raise ArgumentError, "'left' must less than 'right'"
26
+ end
27
+ return
28
+ end
29
+
30
+ raise ArgumentError, "'left' and 'right' must be the same type."
31
+ end
32
+
33
+ if @unit == :month
34
+ unless Task::MONTH.has_key?(@left)
35
+ raise ArgumentError, "#{left} must be a Symbol defined in Task::MONTH"
36
+ end
37
+ return
38
+ end
39
+
40
+ unless @left.is_a?(Integer) && @right.is_a?(Integer)
41
+ raise TypeError, "both 'left' and 'right' need to be Symbol or Integer"
42
+ end
43
+
44
+ unless @left < @right
45
+ raise ArgumentError, "'left' must less than 'right'"
46
+ end
47
+
48
+ if @unit == :minute && (@left < 0 || @right > 59)
49
+ raise ArgumentError, "'left' and 'right' for 'minute' must >= 0 and <= 59"
50
+ end
51
+
52
+ if @unit == :hour && (@left < 0 || @right > 23)
53
+ raise ArgumentError, "'left', 'right' for 'hour' must >= 0 and <= 23"
54
+ end
55
+
56
+ if @unit == :year && @left < 0
57
+ raise ArgumentError, "'left' must greater than 0"
58
+ end
59
+ end
60
+
61
+ def left_value
62
+ if (Task::DAY.has_key?(@left))
63
+ return Task::DAY[@left]
64
+ end
65
+ if (Task::WEEK.has_key?(@left))
66
+ return Task::WEEK[@left]
67
+ end
68
+ if (Task::MONTH.has_key?(@left))
69
+ return Task::MONTH[@left]
70
+ end
71
+
72
+ unless @left != nil && @left.is_a?(Integer)
73
+ return -1
74
+ end
75
+
76
+ return @left
77
+ end
78
+
79
+ def right_value
80
+ if (Task::DAY.has_key?(@right))
81
+ return Task::DAY[@right]
82
+ end
83
+ if (Task::WEEK.has_key?(@right))
84
+ return Task::WEEK[@right]
85
+ end
86
+ if (Task::MONTH.has_key?(@right))
87
+ return Task::MONTH[@right]
88
+ end
89
+
90
+ unless @right != nil && @right.is_a?(Integer)
91
+ return -1
92
+ end
93
+
94
+ return @right
95
+ end
96
+
97
+ def is_week_value?
98
+ if @unit == :day && Task::WEEK.has_key?(@left) && Task::WEEK.has_key?(@right)
99
+ return true
100
+ end
101
+ return false
102
+ end
103
+
104
+ def is_conform_rule?(last_exec_time)
105
+ current = Time.now
106
+ left = left_value
107
+ right = right_value
108
+ result = false
109
+ case @unit
110
+ when :year then
111
+ result = left <= current.year >= left && current.year <= right
112
+ when :month then
113
+ result = left <= current.month && current.month <= right
114
+ when :day then
115
+ if is_week_value?
116
+ result = (left % TaskLoop::WEEK_BASE) <= current.wday && current.wday <= (right % TaskLoop::WEEK_BASE)
117
+ else
118
+ result = left <= current.day && current.day <= right
119
+ end
120
+ when :hour then
121
+ result = left <= current.hour && current.hour <= right
122
+ end
123
+ return result
124
+ end
125
+
126
+ def desc
127
+ super + " #{left}, #{right}"
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,47 @@
1
+ module TaskLoop
2
+ class DateListRule < Rule
3
+ require 'time'
4
+
5
+ attr_writer :dates
6
+
7
+ def dates
8
+ @dates ||= []
9
+ end
10
+
11
+ def dates_values
12
+ values = []
13
+ dates.each do |date|
14
+ date_format = "%Y-%m-%d"
15
+ date_object = Time.strptime(date, date_format)
16
+ values.push(date_object)
17
+ end
18
+ return values
19
+ end
20
+
21
+ def initialize(unit, dates)
22
+ super unit
23
+ unless dates != nil && dates.length > 0
24
+ raise ArgumentError, "dates arguments need at least one value."
25
+ end
26
+ @dates = dates
27
+ end
28
+
29
+ def is_week_value?
30
+ return false
31
+ end
32
+
33
+ def is_conform_rule?(last_exec_time)
34
+ current = Time.now
35
+ result = false
36
+
37
+ dates_values.each do |date|
38
+ result = result || (date.year == current.year && date.month == current.month && date.day == current.day)
39
+ end
40
+ return result
41
+ end
42
+
43
+ def desc
44
+ super + "; date_list: #{dates.join(', ')}"
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,19 @@
1
+ module TaskLoop
2
+ class DefaultRule < Rule
3
+ def initialize(unit)
4
+ super unit
5
+ end
6
+
7
+ def is_week_value?
8
+ return false
9
+ end
10
+
11
+ def is_conform_rule?(last_exec_time)
12
+ return true
13
+ end
14
+
15
+ def desc
16
+ super + "; default rule"
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,26 @@
1
+ module TaskLoop
2
+ class IntervalRule < Rule
3
+
4
+ attr_accessor :interval
5
+
6
+ def initialize(unit, interval)
7
+ super unit
8
+ @interval = interval
9
+ end
10
+
11
+ def is_week_value?
12
+ return false
13
+ end
14
+
15
+ def is_conform_rule?(last_exec_time)
16
+ # interval rule is different for other rules. It should be calculated by combining the interval times of all units.
17
+ # So here returns false
18
+ return false
19
+ end
20
+
21
+ def desc
22
+ super + "; interval: #{interval}"
23
+ end
24
+ end
25
+
26
+ end
@@ -0,0 +1,25 @@
1
+ module TaskLoop
2
+ class LoopRule < Rule
3
+
4
+ attr_accessor :count
5
+
6
+ def initialize(unit, count)
7
+ super unit
8
+ @count = count
9
+ end
10
+
11
+ def is_week_value?
12
+ return false
13
+ end
14
+
15
+ def is_conform_rule?(last_exec_time)
16
+ # loop rule is different for other rules. It should based on task loop file.
17
+ # So here returns false
18
+ return false
19
+ end
20
+
21
+ def desc
22
+ super + "; loop: #{count}"
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,34 @@
1
+ module TaskLoop
2
+ class Rule
3
+
4
+ UNIT = {
5
+ :unknown => 0,
6
+ :minute => 1, # support interval/specific syntax
7
+ :hour => 2, # support interval/scope/specific syntax
8
+ :day => 3, # support interval/scope/specific syntax
9
+ :month => 4, # support interval/scope/specific syntax
10
+ :year => 5, # support interval/scope/specific syntax
11
+ :loop => 7, # only support loop syntax
12
+ :date => 8, # only support date list syntax
13
+ :time => 9, # only support time list syntax
14
+ }
15
+
16
+ attr_accessor :unit
17
+
18
+ def initialize(unit = :unknown)
19
+ @unit = unit
20
+ end
21
+
22
+ def is_week_value?
23
+ raise NotImplementedError, 'subclass need implement this method!'
24
+ end
25
+
26
+ def is_conform_rule?(last_exec_time)
27
+ raise NotImplementedError, 'subclass need implement this method!'
28
+ end
29
+
30
+ def desc
31
+ "unit: #{unit.to_s}"
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,22 @@
1
+ module TaskLoop
2
+
3
+ class ScopeRule < Rule
4
+
5
+ SCOPE = {
6
+ :before => 0,
7
+ :between => 1,
8
+ :after => 2,
9
+ }
10
+
11
+ attr_accessor :scope
12
+
13
+ def initialize(unit, scope)
14
+ super unit
15
+ @scope = scope
16
+ end
17
+
18
+ def desc
19
+ super + "; scope: #{scope.to_s}"
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,64 @@
1
+ module TaskLoop
2
+
3
+ class SpecificRule < Rule
4
+
5
+ attr_accessor :value
6
+
7
+ def initialize(unit, value)
8
+ super unit
9
+ @value = value
10
+ end
11
+
12
+ def value_value
13
+ if (Task::DAY.has_key?(@value))
14
+ return Task::DAY[@value]
15
+ end
16
+ if (Task::WEEK.has_key?(@value))
17
+ return Task::WEEK[@value]
18
+ end
19
+ if (Task::MONTH.has_key?(@value))
20
+ return Task::MONTH[@value]
21
+ end
22
+
23
+ unless @value != nil && @value.is_a?(Integer)
24
+ return -1
25
+ end
26
+
27
+ return @value
28
+ end
29
+
30
+ def is_week_value?
31
+ if @unit == :day && Task::WEEK.has_key?(@value)
32
+ return true
33
+ end
34
+ return false
35
+ end
36
+
37
+ def is_conform_rule?(last_exec_time)
38
+ current = Time.now
39
+ value = value_value
40
+ result = false
41
+ case @unit
42
+ when :year then
43
+ result = current.year == value
44
+ when :month then
45
+ result = current.month == value
46
+ when :day then
47
+ if is_week_value?
48
+ result = current.wday == (value % TaskLoop::WEEK_BASE)
49
+ else
50
+ result = current.day == value
51
+ end
52
+ when :hour then
53
+ result = current.hour == value
54
+ when :minute then
55
+ result = current.min == value
56
+ end
57
+ return result
58
+ end
59
+
60
+ def desc
61
+ super + "; specific: #{value}"
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,49 @@
1
+ module TaskLoop
2
+ class TimeListRule < Rule
3
+
4
+ require 'time'
5
+
6
+ attr_writer :times
7
+
8
+ def times
9
+ @times ||= []
10
+ end
11
+
12
+ def times_values
13
+ values = []
14
+ times.each do |time|
15
+ time_format = "%H:%M:%S"
16
+ time_object = Time.strptime(time, time_format)
17
+ values.push(time_object)
18
+ end
19
+ return values
20
+ end
21
+
22
+ def initialize(unit, times)
23
+ super unit
24
+ unless times != nil && times.length > 0
25
+ raise ArgumentError, "times arguments need at least one value."
26
+ end
27
+
28
+ @times = times
29
+ end
30
+
31
+ def is_week_value?
32
+ return false
33
+ end
34
+
35
+ def is_conform_rule?(last_exec_time)
36
+ current = Time.now
37
+ result = false
38
+
39
+ times_values.each do |time|
40
+ result = result || (time.hour == current.hour && time.min == current.min)
41
+ end
42
+ return result
43
+ end
44
+
45
+ def desc
46
+ super + "; time_list: #{times.join(', ')}"
47
+ end
48
+ end
49
+ end