tab_keeper 0.1.0 → 0.2.0
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8ba88f83d4c927a0292c8b47f8f2d2141de23b0
|
4
|
+
data.tar.gz: 837513550403d5cd3be0f680bad666396394323b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2cb9a5365b000ab3a1f74fe75365f441ac494b0fa15478c297007370c59a2d4eac0a0981d5a19578a498e6cf047199e80523f34f4b7b550e08d229e1c2328001
|
7
|
+
data.tar.gz: bb7ce75b083aab8e8ee56e09ff1a48cca4a1156ab3a9a943a8493dc2c928c087fe1c06f14ec7a2d48cbd471200d6686d97355a940547aef75e9a18fbb25d2174
|
data/lib/tab_keeper/generator.rb
CHANGED
@@ -5,11 +5,34 @@ module TabKeeper
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def generate(job_list, **options)
|
8
|
+
rows = rows(job_list, **options)
|
9
|
+
validate_rows!(rows)
|
10
|
+
rows.join("\n\n") + "\n"
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def validate_rows!(rows)
|
16
|
+
too_long_rows = rows.reject { |row| row.length < 900 }
|
17
|
+
return unless too_long_rows.any?
|
18
|
+
raise "The following rows are too long for a cron file, and may be truncated:\n" \
|
19
|
+
"#{too_long_rows.join("\n\n")}"
|
20
|
+
end
|
21
|
+
|
22
|
+
def rows(job_list, **options)
|
8
23
|
job_list.map do |job, timing|
|
9
|
-
timing + " " +
|
10
|
-
|
11
|
-
|
12
|
-
|
24
|
+
timing + " " + cron_escape(apply_pipeline(job, timing, **options))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def apply_pipeline(job, timing, **options)
|
29
|
+
@pipeline.reduce(nil) do |previous, pipe|
|
30
|
+
pipe.new(previous, job: job, timing: timing, **options).to_s
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def cron_escape(input)
|
35
|
+
input.chars.map { |char| char == '%' ? "\\%" : char }.join
|
13
36
|
end
|
14
37
|
end
|
15
38
|
end
|
@@ -20,7 +20,7 @@ module TabKeeper
|
|
20
20
|
# Normalise the job name: if it's an array take the first thing, then get the last
|
21
21
|
# thing after a "::" (if it's a class name), or a "/" (if it's a script, and removes
|
22
22
|
# the need to escape yay)
|
23
|
-
job_name = Array(@job).first.to_s.split(/((::)|\/)/).last
|
23
|
+
job_name = Array(@job).first.to_s.split(/((::)|\/)/).last.split(/[^\w\d]/).first
|
24
24
|
@job_name = job_name_proc.call(job_name)
|
25
25
|
@timing = timing
|
26
26
|
@log_directory = log_directory
|
@@ -60,7 +60,7 @@ module TabKeeper
|
|
60
60
|
hour_component,
|
61
61
|
min_component,
|
62
62
|
second_component
|
63
|
-
].compact.join('-')
|
63
|
+
].compact.join('-')
|
64
64
|
end
|
65
65
|
|
66
66
|
def day_component
|
@@ -72,7 +72,7 @@ module TabKeeper
|
|
72
72
|
end
|
73
73
|
|
74
74
|
def min_component
|
75
|
-
'%
|
75
|
+
'%M' if more_than_once_a_day?
|
76
76
|
end
|
77
77
|
|
78
78
|
def second_component
|
data/lib/tab_keeper/version.rb
CHANGED
@@ -10,25 +10,39 @@ RSpec.describe TabKeeper::Generator do
|
|
10
10
|
end.to_a
|
11
11
|
end
|
12
12
|
|
13
|
-
let(:pipeline)
|
13
|
+
let(:pipeline) do
|
14
|
+
[TabKeeper::RailsRunner, TabKeeper::LogRedirection, TabKeeper::LoginShell]
|
15
|
+
end
|
14
16
|
let(:options) do
|
15
17
|
{
|
16
18
|
code_directory: '/path/to/code',
|
17
|
-
rails_env: :production
|
19
|
+
rails_env: :production,
|
20
|
+
log_directory: '/path/to/logs',
|
21
|
+
include_date_in_log_name: true
|
18
22
|
}
|
19
23
|
end
|
20
24
|
|
21
25
|
it do
|
22
26
|
is_expected.to eq <<-CRONTAB
|
23
|
-
*/5 * * * * /bin/bash -l -c 'cd /path/to/code && bin/rails runner -e production '\\''FrequentJob.run'\\'''
|
27
|
+
*/5 * * * * /bin/bash -l -c 'cd /path/to/code && bin/rails runner -e production '\\''FrequentJob.run'\\'' >> /path/to/logs/FrequentJob_`date +\\%Y-\\%m-\\%d-\\%H-\\%M-\\%s`.log 2>&1'
|
24
28
|
|
25
|
-
0 0 * * * /bin/bash -l -c 'cd /path/to/code && bin/rails runner -e production '\\''MidnightJob.run'\\'''
|
29
|
+
0 0 * * * /bin/bash -l -c 'cd /path/to/code && bin/rails runner -e production '\\''MidnightJob.run'\\'' >> /path/to/logs/MidnightJob_`date +\\%Y-\\%m-\\%d`.log 2>&1'
|
26
30
|
|
27
|
-
30 12 * * * /bin/bash -l -c 'cd /path/to/code && bin/rails runner -e production '\\''LunchtimeJob.run'\\'''
|
31
|
+
30 12 * * * /bin/bash -l -c 'cd /path/to/code && bin/rails runner -e production '\\''LunchtimeJob.run'\\'' >> /path/to/logs/LunchtimeJob_`date +\\%Y-\\%m-\\%d`.log 2>&1'
|
28
32
|
|
29
|
-
30 7 * * 1 /bin/bash -l -c 'cd /path/to/code && bin/rails runner -e production '\\''HappyMondayJob.run'\\'''
|
33
|
+
30 7 * * 1 /bin/bash -l -c 'cd /path/to/code && bin/rails runner -e production '\\''HappyMondayJob.run'\\'' >> /path/to/logs/HappyMondayJob_`date +\\%Y-\\%m-\\%d`.log 2>&1'
|
30
34
|
|
31
|
-
15 16 25 * * /bin/bash -l -c 'cd /path/to/code && bin/rails runner -e production '\\''PaydayJob.run'\\'''
|
35
|
+
15 16 25 * * /bin/bash -l -c 'cd /path/to/code && bin/rails runner -e production '\\''PaydayJob.run'\\'' >> /path/to/logs/PaydayJob_`date +\\%Y-\\%m`.log 2>&1'
|
32
36
|
CRONTAB
|
33
37
|
end
|
38
|
+
|
39
|
+
context "when the line gets over 900 characters long" do
|
40
|
+
let(:job_list) do
|
41
|
+
TabKeeper::JobList.new { |tab| tab.daily("A" * 901, hour: 12) }.to_a
|
42
|
+
end
|
43
|
+
|
44
|
+
it "raises" do
|
45
|
+
expect { subject }.to raise_error(/too long/)
|
46
|
+
end
|
47
|
+
end
|
34
48
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
RSpec.describe TabKeeper::LogRedirection do
|
2
2
|
let(:instance) do
|
3
3
|
described_class.new("scripts/thing",
|
4
|
-
job: "scripts/thing",
|
4
|
+
job: "scripts/thing.sh",
|
5
5
|
job_name_proc: job_name_proc,
|
6
6
|
timing: timing,
|
7
7
|
log_directory: "/path/to/logs",
|
@@ -34,7 +34,7 @@ RSpec.describe TabKeeper::LogRedirection do
|
|
34
34
|
it do
|
35
35
|
is_expected.to eq(
|
36
36
|
"scripts/thing >> /path/to/logs/thing_" \
|
37
|
-
"`date
|
37
|
+
"`date +%Y-%m-%d-%H-%M-%s`.log 2>&1")
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -43,7 +43,7 @@ RSpec.describe TabKeeper::LogRedirection do
|
|
43
43
|
it do
|
44
44
|
is_expected.to eq(
|
45
45
|
"scripts/thing >> /path/to/logs/thing_" \
|
46
|
-
"`date
|
46
|
+
"`date +%Y-%m-%d-%H-%M`.log 2>&1")
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
@@ -52,7 +52,7 @@ RSpec.describe TabKeeper::LogRedirection do
|
|
52
52
|
it do
|
53
53
|
is_expected.to eq(
|
54
54
|
"scripts/thing >> /path/to/logs/thing_" \
|
55
|
-
"`date
|
55
|
+
"`date +%Y-%m-%d`.log 2>&1")
|
56
56
|
end
|
57
57
|
|
58
58
|
context "with a separate error file" do
|
@@ -60,8 +60,8 @@ RSpec.describe TabKeeper::LogRedirection do
|
|
60
60
|
it do
|
61
61
|
is_expected.to eq(
|
62
62
|
"scripts/thing " \
|
63
|
-
">> /path/to/logs/thing_`date
|
64
|
-
"2>> /path/to/logs/thing_`date
|
63
|
+
">> /path/to/logs/thing_`date +%Y-%m-%d`.log " \
|
64
|
+
"2>> /path/to/logs/thing_`date +%Y-%m-%d`.error.log")
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
@@ -70,7 +70,7 @@ RSpec.describe TabKeeper::LogRedirection do
|
|
70
70
|
it do
|
71
71
|
is_expected.to eq(
|
72
72
|
"scripts/thing >> /path/to/logs/thing_sadness_" \
|
73
|
-
"`date
|
73
|
+
"`date +%Y-%m-%d`.log 2>&1")
|
74
74
|
end
|
75
75
|
end
|
76
76
|
end
|
@@ -80,7 +80,7 @@ RSpec.describe TabKeeper::LogRedirection do
|
|
80
80
|
it do
|
81
81
|
is_expected.to eq(
|
82
82
|
"scripts/thing >> /path/to/logs/thing_" \
|
83
|
-
"`date
|
83
|
+
"`date +%Y-%m-%d`.log 2>&1")
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
@@ -89,7 +89,7 @@ RSpec.describe TabKeeper::LogRedirection do
|
|
89
89
|
it do
|
90
90
|
is_expected.to eq(
|
91
91
|
"scripts/thing >> /path/to/logs/thing_" \
|
92
|
-
"`date
|
92
|
+
"`date +%Y-%m`.log 2>&1")
|
93
93
|
end
|
94
94
|
end
|
95
95
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tab_keeper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Isaac Seymour
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|