Module: Cronjobs
- Defined in:
- lib/cronjobs.rb,
lib/cronjobs/proxy.rb,
lib/cronjobs/railtie.rb,
lib/cronjobs/version.rb,
lib/cronjobs/definitions.rb,
lib/cronjobs/dsl/actions.rb,
lib/generators/cronjobs/install/install_generator.rb
Defined Under Namespace
Modules: DSL, Generators Classes: Definitions, Proxy, Railtie
Constant Summary collapse
- VERSION =
'4.0.0.1'
Class Attribute Summary collapse
-
.env ⇒ Object
Returns the value of attribute env.
-
.mailto ⇒ Object
Returns the value of attribute mailto.
-
.output ⇒ Object
Returns the value of attribute output.
Class Method Summary collapse
Class Attribute Details
.env ⇒ Object
Returns the value of attribute env.
11 12 13 |
# File 'lib/cronjobs.rb', line 11 def env @env end |
.mailto ⇒ Object
Returns the value of attribute mailto.
11 12 13 |
# File 'lib/cronjobs.rb', line 11 def mailto @mailto end |
.output ⇒ Object
Returns the value of attribute output.
11 12 13 |
# File 'lib/cronjobs.rb', line 11 def output @output end |
Class Method Details
.define(&block) ⇒ Object
13 14 15 |
# File 'lib/cronjobs.rb', line 13 def define(&block) Proxy.new &block end |
.definitions ⇒ Object
17 18 19 |
# File 'lib/cronjobs.rb', line 17 def definitions @definitions ||= Definitions.new end |
.update ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/cronjobs.rb', line 21 def update if current_digest != last_digest Open3.popen2(command) do |stdin, stdout, wait_thr| if mailto.present? stdin << "MAILTO=#{mailto}\n" end definitions.each do |time, action| stdin << "#{time} " if env.present? stdin << "#{env} " end stdin << "bash -lc \"cd #{Rails.root} && #{action} " if output.present? stdin << ">> #{output} 2>> #{output}" else stdin << "2>&1" end stdin << "\"\n" end stdin.close if wait_thr.value.success? FileUtils.mkdir_p digest_path.dirname File.write digest_path, current_digest puts 'Crontab updated' else warn "Couldn't write crontab" end end end end |