hyper-smart-pkg 0.0.1

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 (55) hide show
  1. checksums.yaml +7 -0
  2. data/hyper-smart-pkg.gemspec +11 -0
  3. data/whenever-1.1.2/Appraisals +69 -0
  4. data/whenever-1.1.2/CHANGELOG.md +434 -0
  5. data/whenever-1.1.2/CONTRIBUTING.md +38 -0
  6. data/whenever-1.1.2/Gemfile +11 -0
  7. data/whenever-1.1.2/LICENSE +22 -0
  8. data/whenever-1.1.2/Makefile +5 -0
  9. data/whenever-1.1.2/README.md +350 -0
  10. data/whenever-1.1.2/Rakefile +10 -0
  11. data/whenever-1.1.2/bin/whenever +49 -0
  12. data/whenever-1.1.2/bin/wheneverize +71 -0
  13. data/whenever-1.1.2/gemfiles/activesupport5.0.gemfile +11 -0
  14. data/whenever-1.1.2/gemfiles/activesupport5.1.gemfile +11 -0
  15. data/whenever-1.1.2/gemfiles/activesupport5.2.gemfile +11 -0
  16. data/whenever-1.1.2/gemfiles/activesupport6.0.gemfile +17 -0
  17. data/whenever-1.1.2/gemfiles/activesupport6.1.gemfile +17 -0
  18. data/whenever-1.1.2/gemfiles/activesupport7.0.gemfile +11 -0
  19. data/whenever-1.1.2/gemfiles/activesupport7.1.gemfile +11 -0
  20. data/whenever-1.1.2/gemfiles/activesupport7.2.gemfile +11 -0
  21. data/whenever-1.1.2/gemfiles/activesupport8.0.gemfile +11 -0
  22. data/whenever-1.1.2/gemfiles/activesupport8.1.gemfile +11 -0
  23. data/whenever-1.1.2/lib/whenever/capistrano/v2/hooks.rb +8 -0
  24. data/whenever-1.1.2/lib/whenever/capistrano/v2/recipes.rb +49 -0
  25. data/whenever-1.1.2/lib/whenever/capistrano/v2/support.rb +53 -0
  26. data/whenever-1.1.2/lib/whenever/capistrano/v3/tasks/whenever.rake +56 -0
  27. data/whenever-1.1.2/lib/whenever/capistrano.rb +7 -0
  28. data/whenever-1.1.2/lib/whenever/command_line.rb +171 -0
  29. data/whenever-1.1.2/lib/whenever/cron.rb +181 -0
  30. data/whenever-1.1.2/lib/whenever/job.rb +56 -0
  31. data/whenever-1.1.2/lib/whenever/job_list.rb +186 -0
  32. data/whenever-1.1.2/lib/whenever/numeric.rb +13 -0
  33. data/whenever-1.1.2/lib/whenever/numeric_seconds.rb +48 -0
  34. data/whenever-1.1.2/lib/whenever/os.rb +7 -0
  35. data/whenever-1.1.2/lib/whenever/output_redirection.rb +57 -0
  36. data/whenever-1.1.2/lib/whenever/setup.rb +31 -0
  37. data/whenever-1.1.2/lib/whenever/version.rb +3 -0
  38. data/whenever-1.1.2/lib/whenever.rb +42 -0
  39. data/whenever-1.1.2/test/functional/command_line_test.rb +458 -0
  40. data/whenever-1.1.2/test/functional/output_at_test.rb +246 -0
  41. data/whenever-1.1.2/test/functional/output_default_defined_jobs_test.rb +310 -0
  42. data/whenever-1.1.2/test/functional/output_defined_job_test.rb +113 -0
  43. data/whenever-1.1.2/test/functional/output_description_test.rb +25 -0
  44. data/whenever-1.1.2/test/functional/output_env_test.rb +29 -0
  45. data/whenever-1.1.2/test/functional/output_jobs_for_roles_test.rb +65 -0
  46. data/whenever-1.1.2/test/functional/output_jobs_with_mailto_test.rb +168 -0
  47. data/whenever-1.1.2/test/functional/output_redirection_test.rb +248 -0
  48. data/whenever-1.1.2/test/test_case.rb +32 -0
  49. data/whenever-1.1.2/test/test_helper.rb +51 -0
  50. data/whenever-1.1.2/test/unit/capistrano_support_test.rb +147 -0
  51. data/whenever-1.1.2/test/unit/cron_test.rb +418 -0
  52. data/whenever-1.1.2/test/unit/executable_test.rb +142 -0
  53. data/whenever-1.1.2/test/unit/job_test.rb +114 -0
  54. data/whenever-1.1.2/whenever.gemspec +29 -0
  55. metadata +93 -0
@@ -0,0 +1,186 @@
1
+ module Whenever
2
+ class JobList
3
+ attr_reader :roles
4
+
5
+ def initialize(options)
6
+ @jobs, @env, @set_variables, @pre_set_variables = {}, {}, {}, {}
7
+
8
+ if options.is_a? String
9
+ options = { :string => options }
10
+ end
11
+
12
+ pre_set(options[:set])
13
+
14
+ @roles = options[:roles] || []
15
+
16
+ setup_file = File.expand_path('../setup.rb', __FILE__)
17
+ setup = File.read(setup_file)
18
+ schedule = if options[:string]
19
+ options[:string]
20
+ elsif options[:file]
21
+ File.read(options[:file])
22
+ end
23
+
24
+ instance_eval(setup, setup_file)
25
+ instance_eval(schedule, options[:file] || '<eval>')
26
+ end
27
+
28
+ def set(variable, value)
29
+ variable = variable.to_sym
30
+ return if @pre_set_variables[variable]
31
+
32
+ instance_variable_set("@#{variable}".to_sym, value)
33
+ @set_variables[variable] = value
34
+ end
35
+
36
+ def method_missing(name, *args, &block)
37
+ @set_variables.has_key?(name) ? @set_variables[name] : super
38
+ end
39
+
40
+ def respond_to?(name, include_private = false)
41
+ @set_variables.has_key?(name) || super
42
+ end
43
+
44
+ def env(variable, value)
45
+ @env[variable.to_s] = value
46
+ end
47
+
48
+ def every(frequency, options = {})
49
+ @current_time_scope = frequency
50
+ @options = options
51
+ yield
52
+ end
53
+
54
+ def job_type(name, template)
55
+ singleton_class.class_eval do
56
+ define_method(name) do |task, *args|
57
+ options = { :task => task, :template => template }
58
+ options.merge!(args[0]) if args[0].is_a? Hash
59
+
60
+ options[:mailto] ||= @options.fetch(:mailto, :default_mailto)
61
+
62
+ # :cron_log was an old option for output redirection, it remains for backwards compatibility
63
+ options[:output] = (options[:cron_log] || @cron_log) if defined?(@cron_log) || options.has_key?(:cron_log)
64
+ # :output is the newer, more flexible option.
65
+ options[:output] = @output if defined?(@output) && !options.has_key?(:output)
66
+
67
+ @jobs[options.fetch(:mailto)] ||= {}
68
+ @jobs[options.fetch(:mailto)][@current_time_scope] ||= []
69
+ @jobs[options.fetch(:mailto)][@current_time_scope] << Whenever::Job.new(@set_variables.merge(@options).merge(options))
70
+ end
71
+ end
72
+ end
73
+
74
+ def generate_cron_output
75
+ [environment_variables, cron_jobs].compact.join
76
+ end
77
+
78
+ private
79
+
80
+ #
81
+ # Takes a string like: "variable1=something&variable2=somethingelse"
82
+ # and breaks it into variable/value pairs. Used for setting variables at runtime from the command line.
83
+ # Only works for setting values as strings.
84
+ #
85
+ def pre_set(variable_string = nil)
86
+ return if variable_string.nil? || variable_string == ""
87
+
88
+ pairs = variable_string.split('&')
89
+ pairs.each do |pair|
90
+ next unless pair.index('=')
91
+ variable, value = *pair.split('=')
92
+ unless variable.nil? || variable == "" || value.nil? || value == ""
93
+ variable = variable.strip.to_sym
94
+ set(variable, value.strip)
95
+ @pre_set_variables[variable] = value
96
+ end
97
+ end
98
+ end
99
+
100
+ def environment_variables
101
+ return if @env.empty?
102
+
103
+ output = []
104
+ @env.each do |key, val|
105
+ output << "#{key}=#{val.nil? || val == "" ? '""' : val}\n"
106
+ end
107
+ output << "\n"
108
+
109
+ output.join
110
+ end
111
+
112
+ #
113
+ # Takes the standard cron output that Whenever generates and finds
114
+ # similar entries that can be combined. For example: If a job should run
115
+ # at 3:02am and 4:02am, instead of creating two jobs this method combines
116
+ # them into one that runs on the 2nd minute at the 3rd and 4th hour.
117
+ #
118
+ def combine(entries)
119
+ entries.map! { |entry| entry.split(/ +/, 6) }
120
+ 0.upto(4) do |f|
121
+ (entries.length-1).downto(1) do |i|
122
+ next if entries[i][f] == '*'
123
+ comparison = entries[i][0...f] + entries[i][f+1..-1]
124
+ (i-1).downto(0) do |j|
125
+ next if entries[j][f] == '*'
126
+ if comparison == entries[j][0...f] + entries[j][f+1..-1]
127
+ entries[j][f] += ',' + entries[i][f]
128
+ entries.delete_at(i)
129
+ break
130
+ end
131
+ end
132
+ end
133
+ end
134
+
135
+ entries.map { |entry| entry.join(' ') }
136
+ end
137
+
138
+ def cron_jobs_of_time(time, jobs)
139
+ shortcut_jobs, regular_jobs = [], []
140
+
141
+ jobs.each do |job|
142
+ next unless roles.empty? || roles.any? do |r|
143
+ job.has_role?(r)
144
+ end
145
+ Whenever::Output::Cron.output(time, job, :chronic_options => @chronic_options) do |cron|
146
+ cron << "\n\n"
147
+ cron = (job.description.strip + "\n").gsub(/^(.*)$/, '# \1') + cron unless job.description.to_s.empty?
148
+
149
+ if cron[0,1] == "@"
150
+ shortcut_jobs << cron
151
+ else
152
+ regular_jobs << cron
153
+ end
154
+ end
155
+ end
156
+
157
+ shortcut_jobs.join + combine(regular_jobs).join
158
+ end
159
+
160
+ def cron_jobs
161
+ return if @jobs.empty?
162
+
163
+ output = []
164
+
165
+ # jobs with default mailto's must be output before the ones with non-default mailto's.
166
+ @jobs.delete(:default_mailto) { Hash.new }.each do |time, jobs|
167
+ output << cron_jobs_of_time(time, jobs)
168
+ end
169
+
170
+ @jobs.each do |mailto, time_and_jobs|
171
+ output_jobs = []
172
+
173
+ time_and_jobs.each do |time, jobs|
174
+ output_jobs << cron_jobs_of_time(time, jobs)
175
+ end
176
+
177
+ output_jobs.reject! { |output_job| output_job.empty? }
178
+
179
+ output << "MAILTO=#{mailto}\n\n" unless output_jobs.empty?
180
+ output << output_jobs
181
+ end
182
+
183
+ output.join
184
+ end
185
+ end
186
+ end
@@ -0,0 +1,13 @@
1
+ Numeric.class_eval do
2
+ def respond_to?(method, include_private = false)
3
+ super || Whenever::NumericSeconds.public_method_defined?(method)
4
+ end
5
+
6
+ def method_missing(method, *args, &block)
7
+ if Whenever::NumericSeconds.public_method_defined?(method)
8
+ Whenever::NumericSeconds.new(self).send(method)
9
+ else
10
+ super
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,48 @@
1
+ module Whenever
2
+ class NumericSeconds
3
+ attr_reader :number
4
+
5
+ def self.seconds(number, units)
6
+ new(number).send(units)
7
+ end
8
+
9
+ def initialize(number)
10
+ @number = number.to_i
11
+ end
12
+
13
+ def seconds
14
+ number
15
+ end
16
+ alias :second :seconds
17
+
18
+ def minutes
19
+ number * 60
20
+ end
21
+ alias :minute :minutes
22
+
23
+ def hours
24
+ number * 3_600
25
+ end
26
+ alias :hour :hours
27
+
28
+ def days
29
+ number * 86_400
30
+ end
31
+ alias :day :days
32
+
33
+ def weeks
34
+ number * 604_800
35
+ end
36
+ alias :week :weeks
37
+
38
+ def months
39
+ number * 2_592_000
40
+ end
41
+ alias :month :months
42
+
43
+ def years
44
+ number * 31_557_600
45
+ end
46
+ alias :year :years
47
+ end
48
+ end
@@ -0,0 +1,7 @@
1
+ module Whenever
2
+ module OS
3
+ def self.solaris?
4
+ (/solaris/ =~ RUBY_PLATFORM)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,57 @@
1
+ module Whenever
2
+ module Output
3
+ class Redirection
4
+ def initialize(output)
5
+ @output = output
6
+ end
7
+
8
+ def to_s
9
+ return '' unless defined?(@output)
10
+ case @output
11
+ when String then redirect_from_string
12
+ when Hash then redirect_from_hash
13
+ when NilClass then ">> /dev/null 2>&1"
14
+ when Proc then @output.call
15
+ else ''
16
+ end
17
+ end
18
+
19
+ protected
20
+
21
+ def stdout
22
+ return unless @output.has_key?(:standard)
23
+ @output[:standard].nil? ? '/dev/null' : @output[:standard]
24
+ end
25
+
26
+ def stderr
27
+ return unless @output.has_key?(:error)
28
+ @output[:error].nil? ? '/dev/null' : @output[:error]
29
+ end
30
+
31
+ def redirect_from_hash
32
+ case
33
+ when stdout == '/dev/null' && stderr == '/dev/null'
34
+ "> /dev/null 2>&1"
35
+ when stdout && stderr == '/dev/null'
36
+ ">> #{stdout} 2> /dev/null"
37
+ when stdout && stderr
38
+ ">> #{stdout} 2>> #{stderr}"
39
+ when stderr == '/dev/null'
40
+ "2> /dev/null"
41
+ when stderr
42
+ "2>> #{stderr}"
43
+ when stdout == '/dev/null'
44
+ "> /dev/null"
45
+ when stdout
46
+ ">> #{stdout}"
47
+ else
48
+ ''
49
+ end
50
+ end
51
+
52
+ def redirect_from_string
53
+ ">> #{@output} 2>&1"
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,31 @@
1
+ # Environment variable defaults to RAILS_ENV
2
+ set :environment_variable, "RAILS_ENV"
3
+ # Environment defaults to the value of RAILS_ENV in the current environment if
4
+ # it's set or production otherwise
5
+ set :environment, ENV.fetch("RAILS_ENV", "production")
6
+ # Path defaults to the directory `whenever` was run from
7
+ set :path, Whenever.path
8
+
9
+ # Custom Chronic configuration for time parsing, empty by default
10
+ # Full list of options at: https://github.com/mojombo/chronic/blob/master/lib/chronic/parser.rb
11
+ set :chronic_options, {}
12
+
13
+ # All jobs are wrapped in this template.
14
+ # http://blog.scoutapp.com/articles/2010/09/07/rvm-and-cron-in-production
15
+ set :job_template, "/bin/bash -l -c ':job'"
16
+
17
+ set :runner_command, case
18
+ when Whenever.bin_rails?
19
+ "bin/rails runner"
20
+ when Whenever.script_rails?
21
+ "script/rails runner"
22
+ else
23
+ "script/runner"
24
+ end
25
+
26
+ set :bundle_command, Whenever.bundler? ? "bundle exec" : ""
27
+
28
+ job_type :command, ":task :output"
29
+ job_type :rake, "cd :path && :environment_variable=:environment :bundle_command rake :task --silent :output"
30
+ job_type :script, "cd :path && :environment_variable=:environment :bundle_command script/:task :output"
31
+ job_type :runner, "cd :path && :bundle_command :runner_command -e :environment ':task' :output"
@@ -0,0 +1,3 @@
1
+ module Whenever
2
+ VERSION = '1.1.2'
3
+ end
@@ -0,0 +1,42 @@
1
+ require "whenever/version"
2
+ require 'whenever/numeric'
3
+ require 'whenever/numeric_seconds'
4
+ require 'whenever/job_list'
5
+ require 'whenever/job'
6
+ require 'whenever/command_line'
7
+ require 'whenever/cron'
8
+ require 'whenever/output_redirection'
9
+ require 'whenever/os'
10
+
11
+ module Whenever
12
+ def self.cron(options)
13
+ Whenever::JobList.new(options).generate_cron_output
14
+ end
15
+
16
+ def self.seconds(number, units)
17
+ Whenever::NumericSeconds.seconds(number, units)
18
+ end
19
+
20
+ def self.path
21
+ Dir.pwd
22
+ end
23
+
24
+ def self.bin_rails?
25
+ File.exist?(File.join(path, 'bin', 'rails'))
26
+ end
27
+
28
+ def self.script_rails?
29
+ File.exist?(File.join(path, 'script', 'rails'))
30
+ end
31
+
32
+ def self.bundler?
33
+ File.exist?(File.join(path, 'Gemfile'))
34
+ end
35
+
36
+ def self.update_cron options
37
+ o = { 'update' => true, 'console' => false}
38
+ o.merge! options if options
39
+ Whenever::CommandLine.execute o
40
+ end
41
+
42
+ end