lib/cronicle/driver.rb in cronicle-0.1.4 vs lib/cronicle/driver.rb in cronicle-0.1.5

- old
+ new

@@ -52,11 +52,24 @@ else log_for_cronicle(:info, log_msg, log_opts) end upload_script(temp_dir, name, job[:content]) do |temp_script| - command = sudo(:_execute, temp_script, :user => user, :raise_on_non_zero_exit => false) + exec_opts = {:user => user, :raise_on_non_zero_exit => false} + command = nil + + if job[:bundle] + mkgemfile(user, name, job[:bundle], temp_dir) + bundle(user, name, temp_dir) + + with_bundle(user, name, temp_dir) do + command = sudo(:_execute, bundler_path, :exec, temp_script, exec_opts) + end + else + command = sudo(:_execute, temp_script, exec_opts) + end + out = command.full_stdout Cronicle::Utils.remove_prompt!(out) host_user_job = {:host => host.hostname, :user => user, :job => name} put_log = proc do |level, opts| @@ -77,17 +90,31 @@ end end end def create_job(user, name, job) + execute do + if job[:bundle] + mkgemfile(user, name, job[:bundle]) + bundle(user, name) + end + end + create_or_update_job(user, name, job) end def update_job(user, name, job, script) job_content = job[:content].chomp script_content = script[:content].chomp + execute do + if job[:bundle] + mkgemfile(user, name, job[:bundle]) + bundle(user, name) + end + end + if [:schedule, :content].any? {|k| job[k].chomp != script[k].chomp } create_or_update_job(user, name, job, script) end end @@ -112,11 +139,11 @@ temp_entry = temp_script + '.entry' sudo(:execute, :mkdir, '-p', user_libexec_dir(user)) sudo(:execute, :cp, temp_script, libexec_script) sudo(:execute, :touch, user_crontab(user)) delete_cron_entry(user, name) - add_cron_entry(user, name, job[:schedule], user_temp_dir) + add_cron_entry(user, name, job[:schedule], user_temp_dir, job[:bundle]) end end end end end @@ -133,9 +160,10 @@ log_for_cronicle(:info, log_msg, log_opts) unless host.options[:dry_run] delete_cron_entry(user, name) sudo(:execute, :rm, '-f', script[:path], :raise_on_non_zero_exit => false) + sudo(:execute, :rm, '-rf', gemfile_dir(user, name), :raise_on_non_zero_exit => false) end end end end end