cronjobs 0.1.0 → 4.0.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f8ddafda85e8d9d71a19a2ecf0953ebb9ed35f98
4
- data.tar.gz: 51be9250826fb3d6c10310b3268e09ad49ef201f
3
+ metadata.gz: 4860a94cf2030456ed49a7f161106bd3af6ce5c9
4
+ data.tar.gz: 642cecf163c050b6a70d3339fcd1f01c2c9b7d8f
5
5
  SHA512:
6
- metadata.gz: 620601e1fe07898e92280139fb5f6cfd30c545cbc34bf28e4b9d68636ae1fbd7c78f96633e64df1746d139373032e8a812dc26b61d70c0526414ef226f73dfc6
7
- data.tar.gz: 08b218584e62c289c69f911284ac7ddf4c171fc62c0fced9885d42286e6b57fb84012ff072ec6ec076a8ff7029e609f7a4bca7d8c13771c1cb1cb69f9f06b410
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
@@ -18,7 +18,7 @@ module Cronjobs
18
18
  end
19
19
 
20
20
  def every(time, &block)
21
- Cronjobs.add time, DSL::Actions.new(&block).to_a
21
+ Cronjobs.definitions.add time, DSL::Actions.new(&block).to_a
22
22
  end
23
23
 
24
24
  end
@@ -1,9 +1,13 @@
1
1
  module Cronjobs
2
2
  class Railtie < Rails::Railtie
3
3
 
4
- initializer :cronjobs do
4
+ config.after_initialize do
5
5
  load Rails.root.join('config/cronjobs.rb')
6
6
  end
7
7
 
8
+ rake_tasks do
9
+ load 'tasks/cronjobs.rake'
10
+ end
11
+
8
12
  end
9
13
  end
@@ -1,3 +1,5 @@
1
1
  module Cronjobs
2
- VERSION = '0.1.0'
2
+
3
+ VERSION = '4.0.0.0'
4
+
3
5
  end
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(&block)
14
+ Proxy.new &block
13
15
  end
14
16
 
15
- def add(time, actions)
16
- registry << [time, actions]
17
+ def definitions
18
+ @definitions ||= Definitions.new
17
19
  end
18
20
 
19
- def check
21
+ def update
20
22
  if current_digest != last_digest
21
- write
22
- end
23
- end
24
-
25
- def write
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
- end
45
- stdin.close
46
- if wait_thr.value.success?
47
- FileUtils.mkdir_p digest_path.dirname
48
- File.write digest_path, current_digest
49
- puts 'Crontab updated'
50
- else
51
- warn "Couldn't write crontab"
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
@@ -1,5 +1,5 @@
1
1
  namespace :cronjobs do
2
- task check: :environment do
3
- Cronjobs.check
2
+ task update: :environment do
3
+ Cronjobs.update
4
4
  end
5
5
  end
@@ -1,17 +1,19 @@
1
1
  require 'test_helper'
2
2
 
3
- class CronjobsTest < ActiveSupport::TestCase
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 'write' do
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
- Cronjobs.write
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
- <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
-
11
- <%= yield %>
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>
@@ -1,3 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
+
2
3
  ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
4
  load Gem.bin_path('bundler', 'bundle')
data/test/dummy/bin/rails CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+
2
3
  APP_PATH = File.expand_path('../../config/application', __FILE__)
3
4
  require_relative '../config/boot'
4
5
  require 'rails/commands'
data/test/dummy/bin/rake CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+
2
3
  require_relative '../config/boot'
3
4
  require 'rake'
4
5
  Rake.application.run
data/test/dummy/bin/setup CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+
2
3
  require 'pathname'
3
4
 
4
5
  # path to your application root.
@@ -1,4 +1,4 @@
1
- Dummy::Application.configure do
1
+ Rails.application.configure do
2
2
  # Settings specified here will take precedence over those in config/application.rb.
3
3
 
4
4
  # In the development environment your application's code is reloaded on
@@ -1,4 +1,4 @@
1
- Dummy::Application.configure do
1
+ Rails.application.configure do
2
2
  # Settings specified here will take precedence over those in config/application.rb.
3
3
 
4
4
  # Code is not reloaded between requests.
@@ -1,4 +1,4 @@
1
- Dummy::Application.configure do
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 = true
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: 921ea9f25943669d3a4b0a6c8762cb6a97a00c42732c84b3a4c80900d4f2be79081cad03e0ec8d5d0f2f293874b2bbd04c1444e7a6d6b9147de8f4ffb3acff11
14
+ secret_key_base: 2c1c8d4cbaa726b21aa6483b7d556125f4897508e2b94f8b3ddaec675168382c9b3b6eb5a9359d2fade03f539c16ac1ef905891c2410f2fd00b83b76c1666feb
15
15
 
16
16
  test:
17
- secret_key_base: 0e085a62fbfd58069441e0eb7dd8c3d0a7035017443181a5fba2c04041a03f8d0d427216ac56a51da79125898d125bb9fb8badb48404919fe3188eb309231570
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.