Module: Winever::WheneverInterface

Defined in:
lib/winever/whenever_interface.rb

Class Method Summary collapse

Class Method Details

.all_cron_entries(options = {}) ⇒ Object



42
43
44
45
# File 'lib/winever/whenever_interface.rb', line 42

def self.all_cron_entries options={}
  # Array of CronEntry containing only the entry that we support.
  Winever::CronEntry.from_cron_output(raw_cron(options), true)
end

.cron(options = {}) ⇒ Object



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
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/winever/whenever_interface.rb', line 47

def self.cron options={}
  # Content of a printable cron in internal Winever format. Also displays entry that are not handled and why.
  entries = all_cron_entries(options)
  valid_entries = entries.select(&:valid?)
  invalid_entries = entries.reject(&:valid?)


  output = "# Valid tasks for Winever in internal format:\n"
  if !valid_entries.empty?
    output << valid_entries.map(&:cron_line).join("\n\n")
  else
    output << "No valid entries"
  end
  output << "\n\n"

  if !invalid_entries.empty?
    output << "\n# Invalid entries for Winever in internal format:\n"
    invalid_entries.each do |invalid_entry|
      output << "# #{invalid_entry.invalid_reason}\n"
      output << "#{invalid_entry.cron_line}\n\n"
    end
  end

  if !existing_tasks_to_remove.empty?
    if existing_tasks_to_remove.size <= 15
      output << "\n# Additionnal task names that will be removed if they exist:\n"
      existing_tasks_to_remove.each do |path|
        output << "# - #{path}\n"
      end
    else
      output << "\n# Additionnal task names that will be removed if they exist:\n"
      output << "#  (More than #{15} task names, not displaying.)\n"
    end
    output << "\n"
  end
  output
end

.existing_tasks_to_removeObject



12
13
14
# File 'lib/winever/whenever_interface.rb', line 12

def self.existing_tasks_to_remove
  @existing_tasks_to_remove ||= []
end

.raw_cron(options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/winever/whenever_interface.rb', line 16

def self.raw_cron options={}
  # The output of whenever with the custom job_types and job_template.
  options[:file]       ||= 'config/schedule.rb'
  options[:cut]        ||= 0
  options[:identifier] ||= File.expand_path(options[:file])

  schedule = if options[:string]
               options[:string]
             elsif options[:file]
               File.read(options[:file])
             end

  # Prepending out own setup for the schedule to override the existing job_types and job_template.
  options[:string] = File.read(File.dirname(__FILE__)+"/setup_schedule.rb") + "\n" + schedule

  @run_from_winever = true
  output = Whenever.cron(options)
  @run_from_winever = false
  output
end

.remove_existing_tasks(*names) ⇒ Object



7
8
9
10
# File 'lib/winever/whenever_interface.rb', line 7

def self.remove_existing_tasks *names
  @existing_tasks_to_remove ||= []
  @existing_tasks_to_remove.concat(names.flatten)
end

.run_from_winever?Boolean

Returns:

  • (Boolean)


3
4
5
# File 'lib/winever/whenever_interface.rb', line 3

def self.run_from_winever?
  @run_from_winever || false
end

.valid_cron_entries(options = {}) ⇒ Object



37
38
39
40
# File 'lib/winever/whenever_interface.rb', line 37

def self.valid_cron_entries options={}
  # Array of CronEntry containing only the entry that we support.
  Winever::CronEntry.from_cron_output(raw_cron(options))
end