clockwork_web 0.0.1

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.

Potentially problematic release.


This version of clockwork_web might be problematic. Click here for more details.

checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8d4554a13250d7249b7074982f164055299db2de
4
+ data.tar.gz: 079e42ce8ce88456cc44d5000a085a88e2c16ce7
5
+ SHA512:
6
+ metadata.gz: 6ba42432d2220db8080cfc978a4c0a39a9f6e0ababe50d6218b976a061b518e8ff75fe1d5858497123262b24ef09922acd3e81e1dd19c0d80d67347ab3799858
7
+ data.tar.gz: 5dc43184b56bc5b15cf5716d4209cf91c05491b2cac070e55eaee6ab90a0d2049e2a4d6eb2efddb5e033161662825a3b5550d47684a01c724126b4443917b40c
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in clockwork_web.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Andrew Kane
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # Clockwork Web
2
+
3
+ A web interface for [Clockwork](https://github.com/tomykaira/clockwork)
4
+
5
+ - see list of jobs
6
+ - see last run
7
+ - disable jobs
8
+
9
+ Screenshot, demo, and better UI coming soon
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application’s Gemfile:
14
+
15
+ ```ruby
16
+ gem 'clockwork_web'
17
+ ```
18
+
19
+ And add it to your `config/routes.rb`.
20
+
21
+ ```ruby
22
+ mount ClockworkWeb::Engine, at: "clockwork"
23
+ ```
24
+
25
+ Be sure to secure the dashboard in production.
26
+
27
+ To see the last run and disable jobs, hook up Redis.
28
+
29
+ ```ruby
30
+ ClockworkWeb.redis = Redis.new
31
+ ```
32
+
33
+ #### Basic Authentication
34
+
35
+ Set the following variables in your environment or an initializer.
36
+
37
+ ```ruby
38
+ ENV["CLOCKWORK_USERNAME"] = "andrew"
39
+ ENV["CLOCKWORK_PASSWORD"] = "secret"
40
+ ```
41
+
42
+ #### Devise
43
+
44
+ ```ruby
45
+ authenticate :user, lambda {|user| user.admin? } do
46
+ mount ClockworkWeb::Engine, at: "clockwork"
47
+ end
48
+ ```
49
+
50
+ ## TODO
51
+
52
+ - demo
53
+ - better design
54
+
55
+ ## Contributing
56
+
57
+ Everyone is encouraged to help improve this project. Here are a few ways you can help:
58
+
59
+ - [Report bugs](https://github.com/ankane/clockwork_web/issues)
60
+ - Fix bugs and [submit pull requests](https://github.com/ankane/clockwork_web/pulls)
61
+ - Write, clarify, or fix documentation
62
+ - Suggest or add new features
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,24 @@
1
+ module ClockworkWeb
2
+ class HomeController < ActionController::Base
3
+ layout false
4
+ helper ClockworkWeb::HomeHelper
5
+
6
+ http_basic_authenticate_with name: ENV["CLOCKWORK_USERNAME"], password: ENV["CLOCKWORK_PASSWORD"] if ENV["CLOCKWORK_PASSWORD"]
7
+
8
+ def index
9
+ @events = Clockwork.manager.instance_variable_get(:@events).sort_by{|e| [e.instance_variable_get(:@period), e.job.to_s] }
10
+ # TODO fetch all disabled jobs and last runs in one call
11
+ end
12
+
13
+ def job
14
+ job = params[:job]
15
+ if params[:enable] == "true"
16
+ ClockworkWeb.enable(job)
17
+ else
18
+ ClockworkWeb.disable(job)
19
+ end
20
+ redirect_to root_path
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,27 @@
1
+ module ClockworkWeb
2
+ module HomeHelper
3
+
4
+ def friendly_period(period)
5
+ if period % 1.day == 0
6
+ "#{period / 1.day} day"
7
+ elsif period % 1.hour == 0
8
+ "#{period / 1.hour} hour"
9
+ elsif period % 1.minute == 0
10
+ "#{period / 1.minute} min"
11
+ else
12
+ "#{period} sec"
13
+ end
14
+ end
15
+
16
+ def last_run(event)
17
+ if ClockworkWeb.redis
18
+ # TODO get all events at once
19
+ timestamp = ClockworkWeb.redis.get("clockwork:last_run:#{event.job}")
20
+ if timestamp
21
+ time_ago_in_words(Time.at(timestamp.to_i))
22
+ end
23
+ end
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,88 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Clockwork</title>
5
+
6
+ <meta charset="utf-8" />
7
+
8
+ <style>
9
+ body {
10
+ font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;
11
+ margin: 0;
12
+ padding: 20px;
13
+ font-size: 14px;
14
+ line-height: 1.4;
15
+ color: #333;
16
+ }
17
+
18
+ a, a:visited, a:active {
19
+ color: #428bca;
20
+ text-decoration: none;
21
+ }
22
+
23
+ a:hover {
24
+ text-decoration: underline;
25
+ }
26
+
27
+ table {
28
+ width: 100%;
29
+ border-collapse: collapse;
30
+ border-spacing: 0;
31
+ margin-bottom: 20px;
32
+ }
33
+
34
+ th {
35
+ text-align: left;
36
+ border-bottom: solid 2px #ddd;
37
+ }
38
+
39
+ table td, table th {
40
+ padding: 8px;
41
+ }
42
+
43
+ td {
44
+ border-top: solid 1px #ddd;
45
+ }
46
+
47
+ .disabled {
48
+ background-color: pink;
49
+ }
50
+ </style>
51
+ </head>
52
+ <body>
53
+ <div class="container">
54
+ <table>
55
+ <thead>
56
+ <tr>
57
+ <th>Job</th>
58
+ <th style="width: 15%;">Period</th>
59
+ <th style="width: 15%;">Last Run</th>
60
+ <th style="width: 15%;">Action</th>
61
+ </tr>
62
+ </thead>
63
+ <tbody>
64
+ <% @events.each do |event| %>
65
+ <% enabled = ClockworkWeb.enabled?(event.job) %>
66
+ <tr class="<%= enabled ? "" : "disabled" %>">
67
+ <td><%= event.job %></td>
68
+ <td>
69
+ <%= friendly_period(event.instance_variable_get(:@period)) %>
70
+ <% at = event.instance_variable_get(:@at) %>
71
+ <% if at %>
72
+ <div>
73
+ <!-- TODO better format -->
74
+ min: <%= at.instance_variable_get(:@min) %>
75
+ hour: <%= at.instance_variable_get(:@hour) %>
76
+ wday: <%= at.instance_variable_get(:@wday) %>
77
+ </div>
78
+ <% end %>
79
+ </td>
80
+ <td><%= last_run(event) %></td>
81
+ <td><%= button_to enabled ? "Disable" : "Enable", home_job_path(job: event.job, enable: !enabled) %></td>
82
+ </tr>
83
+ <% end %>
84
+ </tbody>
85
+ </table>
86
+ </div>
87
+ </body>
88
+ </html>
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'clockwork_web/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "clockwork_web"
8
+ spec.version = ClockworkWeb::VERSION
9
+ spec.authors = ["Andrew Kane"]
10
+ spec.email = ["andrew@chartkick.com"]
11
+ spec.summary = %q{A web interface for Clockwork}
12
+ spec.description = %q{A web interface for Clockwork}
13
+ spec.homepage = "https://github.com/ankane/clockwork_web"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "clockwork"
22
+ spec.add_dependency "robustly"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.7"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,4 @@
1
+ ClockworkWeb::Engine.routes.draw do
2
+ post "home/job"
3
+ root to: "home#index"
4
+ end
@@ -0,0 +1,9 @@
1
+ module ClockworkWeb
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace ClockworkWeb
4
+
5
+ initializer "clockwork_web" do |app|
6
+ require Rails.root.join("clock") # hacky
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module ClockworkWeb
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,43 @@
1
+ require "clockwork_web/version"
2
+
3
+ # dependencies
4
+ require "clockwork"
5
+ require "robustly"
6
+
7
+ # engine
8
+ require "clockwork_web/engine"
9
+
10
+ module ClockworkWeb
11
+ class << self
12
+ attr_accessor :redis
13
+ end
14
+
15
+ def self.enable(job)
16
+ ClockworkWeb.redis.del("clockwork:disabled:#{job}")
17
+ true
18
+ end
19
+
20
+ def self.disable(job)
21
+ ClockworkWeb.redis.set("clockwork:disabled:#{job}", 1)
22
+ true
23
+ end
24
+
25
+ def self.enabled?(job)
26
+ !ClockworkWeb.redis.exists("clockwork:disabled:#{job}")
27
+ end
28
+ end
29
+
30
+ module Clockwork
31
+ on(:before_run) do |t|
32
+ run = true
33
+ safely do
34
+ if ClockworkWeb.redis
35
+ run = ClockworkWeb.enabled?(t.job)
36
+ if run
37
+ ClockworkWeb.redis.set("clockwork:last_run:#{t.job}", Time.now.to_i)
38
+ end
39
+ end
40
+ end
41
+ run
42
+ end
43
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: clockwork_web
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Kane
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: clockwork
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: robustly
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: A web interface for Clockwork
70
+ email:
71
+ - andrew@chartkick.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - app/controllers/clockwork_web/home_controller.rb
82
+ - app/helpers/clockwork_web/home_helper.rb
83
+ - app/views/clockwork_web/home/index.html.erb
84
+ - clockwork_web.gemspec
85
+ - config/routes.rb
86
+ - lib/clockwork_web.rb
87
+ - lib/clockwork_web/engine.rb
88
+ - lib/clockwork_web/version.rb
89
+ homepage: https://github.com/ankane/clockwork_web
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.4.5
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: A web interface for Clockwork
113
+ test_files: []