crontabinator 0.0.2 → 0.0.3

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.
@@ -1,6 +1,6 @@
1
- set :crontab_log_level, "info"
2
1
  set :crontab_logs_path, -> { shared_path.join('log') }
3
2
  set :crontab_templates_path, "templates/crontab"
4
3
  set :crontab_lockfile_path, -> { "#{fetch(:crontab_templates_path)}/crontab.lock" }
5
4
  set :crontab_scripts_path, -> { "#{fetch(:crontab_templates_path)}/scripts.d" }
6
5
  set :crontab_server_scripts_path, -> { current_path.join('script') }
6
+
@@ -6,11 +6,11 @@ namespace :crontab do
6
6
  files = Dir.glob("#{fetch(:crontab_scripts_path)}/*\.erb")
7
7
  set :crontab_script_files, files.collect { |f| File.expand_path(f) }
8
8
  fetch(:crontab_script_files).each do |file|
9
- hash = eval(File.read(file).lines.to_a.shift)
10
- if hash.nil? or hash[:user].nil? or hash[:schedule].nil?
9
+ hash = eval(File.read(file).lines.to_a.shift).deep_symbolize_keys
10
+ if hash.nil? or hash[:user].nil? or hash[:schedule].nil? or hash[:stages].nil?
11
11
  fatal "Error reading the first line of #{file}"
12
12
  fatal "Ensure the first line is a Ruby hash in the form: " +
13
- "\"{ :user => \"www-data\", :schedule => \"* * * * *\" }\""
13
+ "\"{ :user => \"www-data\", :schedule => \"* * * * *\", :stages => [:production, :staging] }\""
14
14
  fatal "Your shebang line directly next"
15
15
  exit
16
16
  end
@@ -51,3 +51,11 @@ namespace :crontab do
51
51
 
52
52
  end
53
53
  end
54
+
55
+ class Object
56
+ def deep_symbolize_keys
57
+ return self.inject({}){|memo,(k,v)| memo[k.to_sym] = v.deep_symbolize_keys; memo} if self.is_a? Hash
58
+ return self.inject([]){|memo,v | memo << v.deep_symbolize_keys; memo} if self.is_a? Array
59
+ return self
60
+ end
61
+ end
@@ -1,7 +1,7 @@
1
1
  namespace :crontab do
2
2
 
3
3
  # sets :user_crontab_hash in the form:
4
- # { :"user" => ["#!/bin/bash", "/bin/echo 'asdf' >> /tmp/test.log"] }
4
+ # { :"username" => ["#!/bin/bash", "/bin/echo 'asdf' >> /tmp/test.log"] }
5
5
  task :read_all_settings => ['crontab:check:scripts'] do
6
6
  run_locally do
7
7
  user_crontab_hash = {}
@@ -9,9 +9,12 @@ namespace :crontab do
9
9
  # Auto entries
10
10
  auto_entries = []
11
11
  fetch(:crontab_script_files).each do |file|
12
- hash = eval(File.read(file).lines.to_a.shift)
13
- path = "#{fetch(:crontab_server_scripts_path)}/#{File.basename(file, '.erb')}"
14
- auto_entries += [{ :user => hash[:user], :schedule => hash[:schedule], :path => path }]
12
+ hash = eval(File.read(file).lines.to_a.shift).deep_symbolize_keys
13
+ hash[:stages] = hash[:stages].collect { |stage| stage.to_sym }
14
+ if hash[:stages].include? fetch(:stage)
15
+ path = "#{fetch(:crontab_server_scripts_path)}/#{File.basename(file, '.erb')}"
16
+ auto_entries += [{ :user => hash[:user], :schedule => hash[:schedule], :path => path }]
17
+ end
15
18
  end
16
19
  auto_entries.each do |entry|
17
20
  name = File.basename(entry[:path], '.erb')
@@ -49,14 +52,17 @@ namespace :crontab do
49
52
  on roles(:cron) do |host|
50
53
  fetch(:crontab_script_files).each do |path|
51
54
  lines = File.read(path).lines.to_a
52
- lines.shift
53
- file = ERB.new(lines.join, nil, '-').result(binding)
54
- as :root do execute("rm", "/tmp/script", "-f") end
55
- upload! StringIO.new(file), "/tmp/script"
56
- final_path = "#{fetch(:crontab_server_scripts_path)}/#{File.basename(path, '.erb')}"
57
- as :root do
58
- execute("mv", "/tmp/script", final_path)
59
- execute("chmod", "750", final_path)
55
+ hash = eval(lines.shift).deep_symbolize_keys
56
+ hash[:stages] = hash[:stages].collect { |stage| stage.to_sym }
57
+ if hash[:stages].include? fetch(:stage).to_sym
58
+ file = ERB.new(lines.join, nil, '-').result(binding)
59
+ as :root do execute("rm", "/tmp/script", "-f") end
60
+ upload! StringIO.new(file), "/tmp/script"
61
+ final_path = "#{fetch(:crontab_server_scripts_path)}/#{File.basename(path, '.erb')}"
62
+ as :root do
63
+ execute("mv", "/tmp/script", final_path)
64
+ execute("chmod", "750", final_path)
65
+ end
60
66
  end
61
67
  end
62
68
  end
@@ -64,10 +70,6 @@ namespace :crontab do
64
70
 
65
71
  desc "Idempotently setup Crontabs."
66
72
  task :setup => ['crontab:check:settings', :read_all_settings, :upload_scripts] do
67
- log_level = SSHKit.config.output_verbosity
68
- log_level = "info" if log_level.nil?
69
- SSHKit.config.output_verbosity = fetch(:crontab_log_level)
70
-
71
73
  on roles(:cron) do |host|
72
74
  # New
73
75
  fetch(:user_crontab_hash).each do |user, lines|
@@ -90,7 +92,7 @@ namespace :crontab do
90
92
  # Old
91
93
  fetch(:crontabs_to_remove).each do |user|
92
94
  as :root do
93
- execute "crontab", "-u", user, "-r"
95
+ test "crontab", "-u", user, "-r"
94
96
  end
95
97
  end
96
98
  content = [
@@ -104,7 +106,6 @@ namespace :crontab do
104
106
  warn "Updated '#{fetch(:crontab_lockfile_path)}', add it to version control"
105
107
  end
106
108
  end
107
- SSHKit.config.output_verbosity = log_level
108
109
  end
109
110
 
110
111
  if Rake::Task.task_defined?("deploy:publishing")
@@ -113,10 +114,6 @@ namespace :crontab do
113
114
 
114
115
  desc "Check the status of the Crontabs."
115
116
  task :status => [:read_all_settings] do
116
- log_level = SSHKit.config.output_verbosity
117
- log_level = "info" if log_level.nil?
118
- SSHKit.config.output_verbosity = fetch(:crontab_log_level)
119
-
120
117
  on roles(:cron) do
121
118
  fetch(:user_crontab_hash).each do |user, _|
122
119
  as :root do
@@ -128,8 +125,6 @@ namespace :crontab do
128
125
  end
129
126
  end
130
127
  end
131
-
132
- SSHKit.config.output_verbosity = log_level
133
128
  end
134
129
 
135
130
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crontabinator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-11-02 00:00:00.000000000 Z
12
+ date: 2015-11-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano