scron 1.0.1 → 1.0.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.
- data/README.md +3 -7
- data/scron.rb +14 -7
- metadata +4 -4
data/README.md
CHANGED
@@ -3,19 +3,17 @@ Description
|
|
3
3
|
|
4
4
|
Scron is a scheduler for laptops/machines which aren't on 24/7.
|
5
5
|
|
6
|
-
|
7
6
|
Installation
|
8
7
|
============
|
9
8
|
|
10
|
-
|
9
|
+
$ gem install scron
|
11
10
|
|
12
11
|
Then configure cron to run it. I recommend every 2 hours, but you can put any
|
13
12
|
interval here:
|
14
13
|
|
15
|
-
|
14
|
+
$ crontab -e
|
16
15
|
0 */2 * * * scron -r
|
17
16
|
|
18
|
-
|
19
17
|
Usage
|
20
18
|
=====
|
21
19
|
|
@@ -40,7 +38,6 @@ entire day, it will run as soon as possible. Here's an example timeline:
|
|
40
38
|
* Th: already ran, nothing happens
|
41
39
|
* Fr: machine is on, cmd1 runs
|
42
40
|
|
43
|
-
|
44
41
|
Notes
|
45
42
|
=====
|
46
43
|
|
@@ -52,9 +49,8 @@ failure and scron will attempt to re-run it again in 2 hours.
|
|
52
49
|
`$HOME/.scronlog` has the stdout, timestamps, and exit status of last
|
53
50
|
scheduled commands.
|
54
51
|
|
55
|
-
|
56
52
|
License
|
57
53
|
=======
|
58
54
|
|
59
|
-
Copyright
|
55
|
+
Copyright Hugh Bien - http://hughbien.com.
|
60
56
|
Released under BSD License, see LICENSE.md for more info.
|
data/scron.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'date'
|
2
2
|
|
3
3
|
class Scron
|
4
|
-
VERSION = '1.0.
|
4
|
+
VERSION = '1.0.2'
|
5
5
|
SCHEDULE_FILE = "#{ENV['HOME']}/.scron"
|
6
6
|
HISTORY_FILE = "#{ENV['HOME']}/.scrondb"
|
7
7
|
LOG_FILE = "#{ENV['HOME']}/.scronlog"
|
@@ -18,17 +18,24 @@ class Scron
|
|
18
18
|
def self.run
|
19
19
|
scron = Scron.new(read(SCHEDULE_FILE), read(HISTORY_FILE))
|
20
20
|
overdue = scron.schedules.select {|s| s.overdue?}
|
21
|
+
nowstr = now.strftime(History::FORMAT)
|
22
|
+
|
23
|
+
logger = File.open(LOG_FILE, "a")
|
24
|
+
logger.puts("=> #{nowstr} running")
|
21
25
|
return if overdue.size == 0
|
22
26
|
|
23
|
-
logger = []
|
24
27
|
overdue.each do |schedule|
|
28
|
+
logger.puts("=> #{nowstr} #{schedule.command} (start)")
|
25
29
|
output = safe_cmd(schedule.command)
|
26
|
-
logger
|
27
|
-
logger
|
28
|
-
|
30
|
+
logger.puts("=> #{nowstr} #{schedule.command} (exit=#{$?.to_i})")
|
31
|
+
logger.puts(output) unless output == ''
|
32
|
+
if $?.to_i == 0
|
33
|
+
scron.history.touch(schedule.command)
|
34
|
+
File.open(HISTORY_FILE, "w") {|f| f.puts scron.history.to_s}
|
35
|
+
end
|
29
36
|
end
|
30
|
-
|
31
|
-
|
37
|
+
ensure
|
38
|
+
logger.close
|
32
39
|
end
|
33
40
|
|
34
41
|
def self.now
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scron
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: .
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: minitest
|
@@ -36,10 +36,10 @@ executables:
|
|
36
36
|
extensions: []
|
37
37
|
extra_rdoc_files: []
|
38
38
|
files:
|
39
|
-
- scron.rb
|
40
39
|
- scron_test.rb
|
41
|
-
-
|
40
|
+
- scron.rb
|
42
41
|
- LICENSE.md
|
42
|
+
- README.md
|
43
43
|
- scron
|
44
44
|
- ./scron
|
45
45
|
homepage: https://github.com/hughbien/scron
|