croner 0.1.1 → 0.1.2
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.
- checksums.yaml +4 -4
- data/lib/croner/capistrano/croner.rake +27 -0
- data/lib/croner/version.rb +1 -1
- data/lib/croner.rb +6 -12
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5608580712caf9811e0603d56922e3b5ccd268fd
|
4
|
+
data.tar.gz: 24e4e395203db4487af53fd49ca09d14d4f08cf8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e39e60f0131f8552c8ec5846108312acd98ec8e2a38ea73791d40d66386b36f43c0d8c3e0f43a05095f576cb0b4aba83c09be9044e640b1ee73498c796e1022
|
7
|
+
data.tar.gz: b5db813a451fb586746fe6eaf8e286452f9d2e32b866e34268ab8dfb0c18a347ff6b9601c659720819694bfcd1e4cebef7d9eeeb4ca38a240699a5d8abd1822b
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'capistrano/version'
|
2
|
+
|
3
|
+
if defined?(Capistrano::VERSION) && Gem::Version.new(Capistrano::VERSION).release >= Gem::Version.new('3.0.0')
|
4
|
+
namespace :croner do
|
5
|
+
desc "Update application's crontab entries using Croner"
|
6
|
+
task :update_crontab do
|
7
|
+
on roles(:db) do
|
8
|
+
within release_path do
|
9
|
+
with rails_env: fetch(:rails_env) do
|
10
|
+
execute :bundle, :exec, :rake, :"croner:update"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
after "deploy:updated", "croner:update_crontab"
|
17
|
+
after "deploy:reverted", "croner:update_crontab"
|
18
|
+
end
|
19
|
+
|
20
|
+
namespace :load do
|
21
|
+
task :defaults do
|
22
|
+
set :croner_roles, ->{ :db }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
else
|
26
|
+
ArgumentError.new('Required Capistrano Version >= 3.0')
|
27
|
+
end
|
data/lib/croner/version.rb
CHANGED
data/lib/croner.rb
CHANGED
@@ -2,17 +2,17 @@ require 'croner/railtie'
|
|
2
2
|
|
3
3
|
module Croner
|
4
4
|
require "open3"
|
5
|
+
|
5
6
|
def self.run
|
6
|
-
|
7
|
-
return {status: false, message: ''} unless File.exist?(Rails.root.join('config', 'croner', 'hosts', `hostname`.delete("\n")))
|
7
|
+
return {status: false, message: "couldn't found cron setting file"} unless File.exist?(Rails.root.join('config', 'croner', 'hosts', `hostname`.delete("\n")))
|
8
8
|
|
9
|
-
#
|
9
|
+
# get cron contents
|
10
10
|
insert_rows = File.read(Rails.root.join('config', 'croner', 'hosts', `hostname`.delete("\n"))).split("\n")
|
11
11
|
|
12
|
-
#
|
12
|
+
# backup current cron contents
|
13
13
|
`crontab -l > cron_#{Time.current.strftime('%Y%m%d%H%M%S')}.bak`
|
14
14
|
|
15
|
-
#
|
15
|
+
# get current cron contents
|
16
16
|
cron_rows = `crontab -l`.split("\n")
|
17
17
|
|
18
18
|
application_name = Rails.application.class.parent_name
|
@@ -22,11 +22,9 @@ module Croner
|
|
22
22
|
start_index = cron_rows.index(cron_start_row)
|
23
23
|
end_index = cron_rows.index(cron_end_row)
|
24
24
|
|
25
|
-
|
26
|
-
return ArgumentError.new('現在のcron設定にCronerによる不正な行が存在しています') unless ((start_index.present? && end_index.present?) || (start_index.blank? && end_index.blank?))
|
25
|
+
return ArgumentError.new('current cron contents has unvalid settings by Croner!') unless ((start_index.present? && end_index.present?) || (start_index.blank? && end_index.blank?))
|
27
26
|
|
28
27
|
if start_index.present? && end_index.present?
|
29
|
-
# 既存の内容を削除
|
30
28
|
cron_rows.slice!((start_index + 1)..(end_index - 1))
|
31
29
|
else
|
32
30
|
start_index = cron_rows.count
|
@@ -34,18 +32,14 @@ module Croner
|
|
34
32
|
cron_rows << cron_end_row
|
35
33
|
end
|
36
34
|
|
37
|
-
# cron設定を挿入
|
38
35
|
cron_rows.insert(start_index + 1, *insert_rows)
|
39
36
|
|
40
|
-
# ファイルに一時保存
|
41
37
|
File.open("cron_tmp", "w") do |f|
|
42
38
|
cron_rows.each{|row| f.puts(row)}
|
43
39
|
end
|
44
40
|
|
45
|
-
# ファイルの内容をcronに出力
|
46
41
|
stdout, stderror, status = Open3.capture3("crontab cron_tmp")
|
47
42
|
|
48
|
-
# ファイルを削除
|
49
43
|
File.delete("cron_tmp")
|
50
44
|
|
51
45
|
if status.success?
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: croner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ykogure
|
@@ -49,6 +49,7 @@ files:
|
|
49
49
|
- README.md
|
50
50
|
- Rakefile
|
51
51
|
- lib/croner.rb
|
52
|
+
- lib/croner/capistrano/croner.rake
|
52
53
|
- lib/croner/railtie.rb
|
53
54
|
- lib/croner/version.rb
|
54
55
|
- lib/tasks/croner_tasks.rake
|