cronjobs 0.1.0 → 4.0.0.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 +4 -4
- data/Rakefile +1 -19
- data/lib/cronjobs/definitions.rb +23 -0
- data/lib/cronjobs/proxy.rb +1 -1
- data/lib/cronjobs/railtie.rb +5 -1
- data/lib/cronjobs/version.rb +3 -1
- data/lib/cronjobs.rb +19 -27
- data/lib/generators/cronjobs/install/install_generator.rb +15 -0
- data/lib/generators/cronjobs/{templates/definitions.rb → install/templates/configuration.rb} +0 -0
- data/lib/tasks/cronjobs.rake +2 -2
- data/test/{cronjobs_test.rb → definition_test.rb} +5 -3
- data/test/dummy/app/views/layouts/application.html.erb +9 -11
- data/test/dummy/bin/bundle +1 -0
- data/test/dummy/bin/rails +1 -0
- data/test/dummy/bin/rake +1 -0
- data/test/dummy/bin/setup +1 -0
- data/test/dummy/config/environments/development.rb +1 -1
- data/test/dummy/config/environments/production.rb +1 -1
- data/test/dummy/config/environments/test.rb +2 -2
- data/test/dummy/config/initializers/wrap_parameters.rb +5 -0
- data/test/dummy/config/secrets.yml +2 -2
- data/test/dummy/log/test.log +34 -1635
- data/test/dummy/public/404.html +57 -63
- data/test/dummy/public/422.html +57 -63
- data/test/dummy/public/500.html +56 -62
- data/test/generator_test.rb +4 -5
- data/test/{tasks_test.rb → task_test.rb} +6 -6
- data/test/test_helper.rb +1 -1
- metadata +10 -11
- data/lib/generators/cronjobs/install_generator.rb +0 -15
- data/test/dummy/log/development.log +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4860a94cf2030456ed49a7f161106bd3af6ce5c9
|
4
|
+
data.tar.gz: 642cecf163c050b6a70d3339fcd1f01c2c9b7d8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22a86992011e5c56126d9a0a5f143ee982d0bfe0ae35cac2e3aaeade257075b9104fe3e3ceb4c59e60a4d0cb74e1c0b57f3b162469394e20567b7c35625de6ea
|
7
|
+
data.tar.gz: 03c2458b96ac1cd5692204374c0cba690c4dd16859d2e9ab27e48d2ea4fa83342b9baaf98b95493bbd6289d1b823403511553dc0cee8a562095bab6472fbe8bb
|
data/Rakefile
CHANGED
@@ -4,26 +4,8 @@ rescue LoadError
|
|
4
4
|
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
5
|
end
|
6
6
|
|
7
|
-
require 'rdoc/task'
|
8
|
-
|
9
|
-
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
-
rdoc.rdoc_dir = 'rdoc'
|
11
|
-
rdoc.title = 'Cronjobs'
|
12
|
-
rdoc.options << '--line-numbers'
|
13
|
-
rdoc.rdoc_files.include('README.rdoc')
|
14
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
-
end
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
7
|
Bundler::GemHelper.install_tasks
|
23
8
|
|
24
|
-
APP_RAKEFILE = File.expand_path('../test/dummy/Rakefile', __FILE__)
|
25
|
-
load 'rails/tasks/engine.rake'
|
26
|
-
|
27
9
|
require 'rake/testtask'
|
28
10
|
|
29
11
|
Rake::TestTask.new(:test) do |t|
|
@@ -31,7 +13,7 @@ Rake::TestTask.new(:test) do |t|
|
|
31
13
|
t.libs << 'test'
|
32
14
|
t.pattern = 'test/**/*_test.rb'
|
33
15
|
t.verbose = false
|
16
|
+
t.warning = false
|
34
17
|
end
|
35
18
|
|
36
|
-
|
37
19
|
task default: :test
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Cronjobs
|
2
|
+
class Definitions
|
3
|
+
|
4
|
+
def each
|
5
|
+
registry.each do |time, actions|
|
6
|
+
actions.each do |action|
|
7
|
+
yield time, action
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def add(time, actions)
|
13
|
+
registry << [time, actions]
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def registry
|
19
|
+
@registry ||= []
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
data/lib/cronjobs/proxy.rb
CHANGED
data/lib/cronjobs/railtie.rb
CHANGED
data/lib/cronjobs/version.rb
CHANGED
data/lib/cronjobs.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'cronjobs/dsl/actions'
|
2
|
+
require 'cronjobs/definitions'
|
2
3
|
require 'cronjobs/proxy'
|
3
4
|
require 'cronjobs/railtie'
|
5
|
+
require 'cronjobs/version'
|
4
6
|
require 'open3'
|
5
7
|
|
6
8
|
module Cronjobs
|
@@ -9,26 +11,20 @@ module Cronjobs
|
|
9
11
|
attr_accessor :env, :mailto, :output
|
10
12
|
|
11
13
|
def define(&block)
|
12
|
-
Proxy.new
|
14
|
+
Proxy.new &block
|
13
15
|
end
|
14
16
|
|
15
|
-
def
|
16
|
-
|
17
|
+
def definitions
|
18
|
+
@definitions ||= Definitions.new
|
17
19
|
end
|
18
20
|
|
19
|
-
def
|
21
|
+
def update
|
20
22
|
if current_digest != last_digest
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
Open3.popen2(command) do |stdin, stdout, wait_thr|
|
27
|
-
if mailto.present?
|
28
|
-
stdin << "MAILTO=#{mailto}\n"
|
29
|
-
end
|
30
|
-
registry.each do |time, actions|
|
31
|
-
actions.each do |action|
|
23
|
+
Open3.popen2(command) do |stdin, stdout, wait_thr|
|
24
|
+
if mailto.present?
|
25
|
+
stdin << "MAILTO=#{mailto}\n"
|
26
|
+
end
|
27
|
+
definitions.each do |time, action|
|
32
28
|
stdin << "#{time} "
|
33
29
|
if env.present?
|
34
30
|
stdin << "#{env} "
|
@@ -41,24 +37,20 @@ module Cronjobs
|
|
41
37
|
end
|
42
38
|
stdin << "\"\n"
|
43
39
|
end
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
40
|
+
stdin.close
|
41
|
+
if wait_thr.value.success?
|
42
|
+
FileUtils.mkdir_p digest_path.dirname
|
43
|
+
File.write digest_path, current_digest
|
44
|
+
puts 'Crontab updated'
|
45
|
+
else
|
46
|
+
warn "Couldn't write crontab"
|
47
|
+
end
|
52
48
|
end
|
53
49
|
end
|
54
50
|
end
|
55
51
|
|
56
52
|
private
|
57
53
|
|
58
|
-
def registry
|
59
|
-
@registry ||= []
|
60
|
-
end
|
61
|
-
|
62
54
|
def command
|
63
55
|
'contrab -'
|
64
56
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module Cronjobs
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < ::Rails::Generators::Base
|
6
|
+
|
7
|
+
source_root File.expand_path('../templates', __FILE__)
|
8
|
+
|
9
|
+
def create_configuration_file
|
10
|
+
copy_file 'configuration.rb', 'config/cronjobs.rb'
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/generators/cronjobs/{templates/definitions.rb → install/templates/configuration.rb}
RENAMED
File without changes
|
data/lib/tasks/cronjobs.rake
CHANGED
@@ -1,17 +1,19 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class DefinitionTest < ActiveSupport::TestCase
|
4
4
|
|
5
5
|
teardown do
|
6
6
|
FileUtils.rm_rf Rails.root.join('tmp')
|
7
7
|
end
|
8
8
|
|
9
|
-
test '
|
9
|
+
test 'update' do
|
10
10
|
output_path = Rails.root.join('tmp/output')
|
11
11
|
FileUtils.mkdir_p output_path.dirname
|
12
12
|
FileUtils.touch output_path
|
13
13
|
Cronjobs.stubs(:command).returns("cat - > #{output_path}")
|
14
|
-
|
14
|
+
silence_stream(STDOUT) do
|
15
|
+
Cronjobs.update
|
16
|
+
end
|
15
17
|
prefix = '* 1 * * * PATH=$PATH:/usr/local/bin bash -lc'
|
16
18
|
redirect = ">> #{Rails.root.join('log/cronjobs.log')} 2>> #{Rails.root.join('log/cronjobs.log')}"
|
17
19
|
output = <<-EOF.strip_heredoc
|
@@ -1,14 +1,12 @@
|
|
1
1
|
<!DOCTYPE html>
|
2
2
|
<html>
|
3
|
-
<head>
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
</head>
|
9
|
-
<body>
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
</body>
|
3
|
+
<head>
|
4
|
+
<title>Dummy</title>
|
5
|
+
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
|
6
|
+
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
<%= yield %>
|
11
|
+
</body>
|
14
12
|
</html>
|
data/test/dummy/bin/bundle
CHANGED
data/test/dummy/bin/rails
CHANGED
data/test/dummy/bin/rake
CHANGED
data/test/dummy/bin/setup
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
Rails.application.configure do
|
2
2
|
# Settings specified here will take precedence over those in config/application.rb.
|
3
3
|
|
4
4
|
# The test environment is used exclusively to run your application's
|
@@ -17,7 +17,7 @@ Dummy::Application.configure do
|
|
17
17
|
config.static_cache_control = 'public, max-age=3600'
|
18
18
|
|
19
19
|
# Show full error reports and disable caching.
|
20
|
-
config.consider_all_requests_local
|
20
|
+
config.consider_all_requests_local = true
|
21
21
|
config.action_controller.perform_caching = false
|
22
22
|
|
23
23
|
# Raise exceptions instead of rendering exception templates.
|
@@ -7,3 +7,8 @@
|
|
7
7
|
ActiveSupport.on_load(:action_controller) do
|
8
8
|
wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
|
9
9
|
end
|
10
|
+
|
11
|
+
# To enable root element in JSON for ActiveRecord objects.
|
12
|
+
# ActiveSupport.on_load(:active_record) do
|
13
|
+
# self.include_root_in_json = true
|
14
|
+
# end
|
@@ -11,10 +11,10 @@
|
|
11
11
|
# if you're sharing your code publicly.
|
12
12
|
|
13
13
|
development:
|
14
|
-
secret_key_base:
|
14
|
+
secret_key_base: 2c1c8d4cbaa726b21aa6483b7d556125f4897508e2b94f8b3ddaec675168382c9b3b6eb5a9359d2fade03f539c16ac1ef905891c2410f2fd00b83b76c1666feb
|
15
15
|
|
16
16
|
test:
|
17
|
-
secret_key_base:
|
17
|
+
secret_key_base: 9dd531171128e7c3d11dd2c5c18c84ba43d29b677043002634a6f4d58bf2687a283b7b6dc6af741d63c3824f11fa1f858010d7c2509a932023f2ece0d3bfe6cf
|
18
18
|
|
19
19
|
# Do not keep production secrets in the repository,
|
20
20
|
# instead read values from the environment.
|