trak3r-crontabr 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.
- data/VERSION.yml +4 -0
- data/lib/crontabr.rb +52 -0
- data/test/crontabr_test.rb +17 -0
- data/test/test_helper.rb +9 -0
- metadata +57 -0
data/VERSION.yml
ADDED
data/lib/crontabr.rb
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
require 'open3'
|
|
2
|
+
|
|
3
|
+
class Crontabr
|
|
4
|
+
|
|
5
|
+
class << self
|
|
6
|
+
|
|
7
|
+
def scheduled?(job_id)
|
|
8
|
+
stdin, stdout, stderr = Open3.popen3('crontab -l')
|
|
9
|
+
while(line = stdout.gets)
|
|
10
|
+
return true if line.include?(tag(job_id))
|
|
11
|
+
end
|
|
12
|
+
return false
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def schedule(job_id, job)
|
|
16
|
+
jobs = [tagged(job_id, job)]
|
|
17
|
+
stdin, stdout, stderr = Open3.popen3('crontab -l')
|
|
18
|
+
while(line = stdout.gets)
|
|
19
|
+
jobs << line unless line.include?(tag(job_id))
|
|
20
|
+
end
|
|
21
|
+
tabbem(jobs)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def unschedule(job_id)
|
|
25
|
+
jobs = []
|
|
26
|
+
stdin, stdout, stderr = Open3.popen3('crontab -l')
|
|
27
|
+
while(line = stdout.gets)
|
|
28
|
+
jobs << line unless line.include?(tag(job_id))
|
|
29
|
+
end
|
|
30
|
+
tabbem(jobs)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
private
|
|
34
|
+
|
|
35
|
+
def tabbem(jobs)
|
|
36
|
+
stdin, stdout, stderr = Open3.popen3('crontab')
|
|
37
|
+
jobs.each do |job|
|
|
38
|
+
stdin.puts job
|
|
39
|
+
end
|
|
40
|
+
stdin.close
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def tagged(job_id, job)
|
|
44
|
+
"#{job} #{tag(job_id)}"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def tag(job_id)
|
|
48
|
+
"# crontabr_#{job_id}"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
|
2
|
+
|
|
3
|
+
class CrontabrTest < Test::Unit::TestCase
|
|
4
|
+
def test_scheduling
|
|
5
|
+
job = "0 1 2 * * echo 'hello world'"
|
|
6
|
+
job_id = 'xyzzy'
|
|
7
|
+
Crontabr.unschedule job_id # start with a clean slate
|
|
8
|
+
assert ! Crontabr.scheduled?(job_id)
|
|
9
|
+
Crontabr.schedule job_id, job
|
|
10
|
+
assert Crontabr.scheduled?(job_id)
|
|
11
|
+
changed_job = "0 1 2 * * echo 'goodbye cruel world'"
|
|
12
|
+
Crontabr.schedule job_id, changed_job
|
|
13
|
+
assert Crontabr.scheduled?(job_id)
|
|
14
|
+
Crontabr.unschedule job_id
|
|
15
|
+
assert ! Crontabr.scheduled?(job_id)
|
|
16
|
+
end
|
|
17
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: trak3r-crontabr
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.2
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Thomas 'Ted' Davis
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2009-02-12 00:00:00 -08:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies: []
|
|
15
|
+
|
|
16
|
+
description: Ruby library for non-destructively adding, removing, and replacing crontab entries.
|
|
17
|
+
email: github@rudiment.net
|
|
18
|
+
executables: []
|
|
19
|
+
|
|
20
|
+
extensions: []
|
|
21
|
+
|
|
22
|
+
extra_rdoc_files: []
|
|
23
|
+
|
|
24
|
+
files:
|
|
25
|
+
- VERSION.yml
|
|
26
|
+
- lib/crontabr.rb
|
|
27
|
+
- test/crontabr_test.rb
|
|
28
|
+
- test/test_helper.rb
|
|
29
|
+
has_rdoc: true
|
|
30
|
+
homepage: http://github.com/trak3r/crontabr
|
|
31
|
+
post_install_message:
|
|
32
|
+
rdoc_options:
|
|
33
|
+
- --inline-source
|
|
34
|
+
- --charset=UTF-8
|
|
35
|
+
require_paths:
|
|
36
|
+
- lib
|
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
38
|
+
requirements:
|
|
39
|
+
- - ">="
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
version: "0"
|
|
42
|
+
version:
|
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: "0"
|
|
48
|
+
version:
|
|
49
|
+
requirements: []
|
|
50
|
+
|
|
51
|
+
rubyforge_project:
|
|
52
|
+
rubygems_version: 1.2.0
|
|
53
|
+
signing_key:
|
|
54
|
+
specification_version: 2
|
|
55
|
+
summary: Ruby library for non-destructively adding, removing, and replacing crontab entries.
|
|
56
|
+
test_files: []
|
|
57
|
+
|