Class: TaskLoop::Task

Inherits:
Object
  • Object
show all
Includes:
TaskDataFile, TaskProperty
Defined in:
lib/taskloop/task/task.rb

Constant Summary collapse

YEAR_MIN =

Time Seconds

365 * 24 * 60
MONTH_MIN =
30 * 24 * 60
DAY_MIN =
24 * 60
HOUR_MIN =
60
@@tasklist =
[]

Constants included from TaskProperty

TaskLoop::TaskProperty::DAY, TaskLoop::TaskProperty::MONTH, TaskLoop::TaskProperty::WEEK

Instance Attribute Summary

Attributes included from TaskDataFile

#data_proj_dir

Attributes included from TaskProperty

#name, #path

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TaskDataFile

#logfile_name, #logfile_path, #loopfile_name, #loopfile_path, #timefile_name, #timefile_path, #write_to_logfile, #write_to_loopfile, #write_to_timefile

Methods included from TaskProperty

#date, #date=, #day, #day=, #end_point, #end_point=, #has_date?, #has_hm?, #has_interval_rule?, #has_time?, #has_week?, #has_ymd?, #hour, #hour=, #last_time, #loop, #loop=, #loop_count, #minute, #minute=, #month, #month=, #start_point, #start_point=, #time, #time=, #week, #week=, #year, #year=

Constructor Details

#initialize {|_self| ... } ⇒ Task

Returns a new instance of Task.

Yields:

  • (_self)

Yield Parameters:



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/taskloop/task/task.rb', line 22

def initialize
  yield self
  check = true
  unless @name
    puts "Error: task name is required.".ansi.red
    puts ""
    check = false
  end
  unless @path
    puts "Error: task path is required.".ansi.red
    puts ""
    check = false
  end
  unless check
    raise TaskArgumentError, "Lack of <required> arguments."
  end
  @@tasklist.push(self)
end

Class Method Details

.tasklistObject



14
15
16
# File 'lib/taskloop/task/task.rb', line 14

def self.tasklist
  @@tasklist
end

.tasklist=(value) ⇒ Object



18
19
20
# File 'lib/taskloop/task/task.rb', line 18

def self.tasklist=(value)
  @@tasklist = value
end

Instance Method Details

#check_all_rules?Boolean



125
126
127
128
129
130
131
132
133
134
135
# File 'lib/taskloop/task/task.rb', line 125

def check_all_rules?
  last_exec_time = last_time

  result = true
  result &&= check_boundary_rule?(last_exec_time)
  result &&= check_interval_rule?(last_exec_time)
  result &&= check_scope_rule?(last_exec_time)
  result &&= check_specific_fule?(last_exec_time)
  result &&= check_loop_rule?(last_exec_time)
  return result
end

#check_rule_conflict?Boolean



73
74
75
76
77
78
79
80
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/taskloop/task/task.rb', line 73

def check_rule_conflict?
  result = true
  # check year/month/day with date, they cannot be set at the same time
  if has_ymd? && has_date?
    puts "Error: #{desc} => <year/month/day> and <date> cannot be set at the same time.".ansi.red
    result = false
  end

  # check hour/minute with time, they cannot be set at the same time
  if has_hm? && has_time?
    puts "Error: #{desc} => <hour/minute> and <time> cannot be set at the same time.".ansi.red
    result = false
  end

  # check rule type

  if has_ymd? && has_hm?
    # check minute/hour/day/month/year. Get the last IntervalRule, than check if there is SpecificRule or ScopeRule before
    rules = [minute, hour, day, month, year]
    rIdx = rules.rindex { |rule| rule.is_a?(IntervalRule) }
    if rIdx != nil
      rules.each_with_index do |rule, index|
        if index < rIdx && (rule.is_a?(ScopeRule) || rule.is_a?(SpecificRule))
          puts "Error: #{desc} => a ScopeRule or a SpecificRule is assigned to a smaller unit while a IntervalRule is assigned to a larger unit.".ansi.red
          result = false
          break
        end
      end
    end
  end

  if has_ymd? && has_time?
    # check year/month/day with time, YMD can not have IntervalRule
    rules = [day, month, year]
    hasInterval = rules.any? { |rule| rule.is_a?(IntervalRule) }
    if hasInterval
      puts "Error: #{desc} => a IntervalRule is assigned to <year/month/day> while <time> is assigned. It is a conflict!".ansi.red
      result = false
    end
  end

  if has_date? && has_hm?
    # it's ok
  end

  if has_date? && has_time?
    # it's ok
  end

  return result
end

#deploy_lint?Boolean

Check and Lint



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/taskloop/task/task.rb', line 44

def deploy_lint?
  result = true
  # check task name uniqueness
  @@tasklist.each do |task|
    if task != self && task.name == @name
      puts "Error: #{task.desc} => there are multiple tasks with the same name in the Taskfile. Please check the task name again.".ansi.red
      result = false
    end
    # only check with the task before self
    if task == self
      break
    end
  end
  # check if task path exists
  unless @path && File.exists?(@path)
    puts "Error: #{desc} => the file in <#{@path}> is not exist. Please check the task path again.".ansi.red
    result = false
  end
  # check task rules conflict
  unless check_rule_conflict?
    puts "Error: #{desc} rule conflicts have been detected above.".ansi.red
    result = false
  end
  unless result
    puts "=============================".ansi.red
  end
  return result
end

#descObject



238
239
240
# File 'lib/taskloop/task/task.rb', line 238

def desc
  "<Task.name: #{@name}, sha1: #{sha1}>"
end

#sha1Object

Sha1 and description



232
233
234
235
236
# File 'lib/taskloop/task/task.rb', line 232

def sha1
  sha1_digest = Digest::SHA1.new
  sha1_digest.update(@name)
  return sha1_digest.hexdigest
end