khronos 0.0.1 → 0.0.2.pre1
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/lib/khronos.rb +0 -1
- data/lib/khronos/server/controller.rb +15 -6
- data/lib/khronos/server/runner.rb +1 -0
- data/lib/khronos/server/scheduler.rb +19 -1
- data/lib/khronos/storage/adapter/activerecord.rb +7 -6
- data/lib/khronos/storage/adapter/mongoid.rb +3 -3
- data/lib/khronos/storage/adapter/mongoid/schedule.rb +0 -1
- data/lib/khronos/version.rb +1 -1
- data/spec/spec_helper.rb +2 -0
- data/spec/tmp/scheduler.db +0 -0
- data/spec/tmp/sqlite3.db +0 -0
- metadata +4 -4
data/lib/khronos.rb
CHANGED
@@ -5,20 +5,29 @@ module Khronos
|
|
5
5
|
|
6
6
|
def initialize
|
7
7
|
@storage = Storage.new
|
8
|
-
@scheduler = Scheduler.new
|
8
|
+
@scheduler = Khronos::Scheduler.new
|
9
9
|
end
|
10
10
|
|
11
11
|
def logger=(logger)
|
12
12
|
puts "WARNING: Not implemented yet."
|
13
13
|
end
|
14
14
|
|
15
|
+
def check_schedule!
|
16
|
+
puts "Check... #{Time.now}"
|
17
|
+
count = 0
|
18
|
+
@scheduler.fetch(Time.now).each do |schedule|
|
19
|
+
schedule.update_attributes(:active => false)
|
20
|
+
schedule.save
|
21
|
+
|
22
|
+
@scheduler.run(schedule)
|
23
|
+
count += 1
|
24
|
+
end
|
25
|
+
puts "Tick. #{count} jobs to run."
|
26
|
+
end
|
27
|
+
|
15
28
|
def start!
|
16
29
|
loop do
|
17
|
-
|
18
|
-
schedule.update_attributes(:status => false)
|
19
|
-
schedule.save
|
20
|
-
@scheduler.run(schedule)
|
21
|
-
end
|
30
|
+
check_schedule!
|
22
31
|
|
23
32
|
#
|
24
33
|
# Sleep 'interval' seconds
|
@@ -6,6 +6,24 @@ module Khronos
|
|
6
6
|
class Scheduler < Sinatra::Base
|
7
7
|
set :storage, Storage.new
|
8
8
|
|
9
|
+
# Introduction
|
10
|
+
get '/' do
|
11
|
+
<<-EOF
|
12
|
+
<html>
|
13
|
+
<head>
|
14
|
+
<title>Khronos #{Khronos::VERSION}</title>
|
15
|
+
</head>
|
16
|
+
<body>
|
17
|
+
<h1>HTTP Job Scheduler Interface.</h1>
|
18
|
+
<p>
|
19
|
+
<a href="http://rubygems.org/gems/khronos">Khronos #{Khronos::VERSION}</a><br />
|
20
|
+
by <a href="https://github.com/endel">Endel Dreyer</a>
|
21
|
+
</p>
|
22
|
+
</body>
|
23
|
+
</html>
|
24
|
+
EOF
|
25
|
+
end
|
26
|
+
|
9
27
|
# Creates a schedule
|
10
28
|
#
|
11
29
|
# @param [String] context application-level identifier
|
@@ -59,7 +77,7 @@ module Khronos
|
|
59
77
|
#
|
60
78
|
# @return [Hash] Context JSON status hash
|
61
79
|
put '/task' do
|
62
|
-
schedule = Storage::Schedule.where({:id => params.delete(
|
80
|
+
schedule = Storage::Schedule.where({:id => params.delete('id')}).first
|
63
81
|
|
64
82
|
# No schedule found for this params.
|
65
83
|
return {}.to_json unless schedule
|
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'active_record'
|
2
1
|
|
3
2
|
module Khronos
|
4
3
|
class Storage
|
@@ -9,12 +8,14 @@ module Khronos
|
|
9
8
|
autoload :ScheduleLog, 'khronos/storage/adapter/activerecord/schedule_log'
|
10
9
|
|
11
10
|
def self.connect!(url)
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
require 'active_record'
|
12
|
+
|
13
|
+
#if File.exists?("config/database.yml")
|
14
|
+
#::ActiveRecord::Base.establish_connection(YAML.load_file("config/database.yml")[ENV['RACK_ENV']])
|
15
|
+
#else
|
16
16
|
::ActiveRecord::Base.establish_connection(url)
|
17
|
-
|
17
|
+
::ActiveRecord::Base.include_root_in_json = false
|
18
|
+
#end
|
18
19
|
|
19
20
|
#
|
20
21
|
# ::ActiveRecord::Base.logger = ::Logger.new(STDOUT)
|
@@ -1,6 +1,3 @@
|
|
1
|
-
require 'mongoid'
|
2
|
-
require 'mongo'
|
3
|
-
|
4
1
|
module Khronos
|
5
2
|
class Storage
|
6
3
|
module Adapter
|
@@ -10,6 +7,9 @@ module Khronos
|
|
10
7
|
autoload :ScheduleLog, 'khronos/storage/adapter/mongoid/schedule_log'
|
11
8
|
|
12
9
|
def self.connect!(uri)
|
10
|
+
require 'mongo'
|
11
|
+
require 'mongoid'
|
12
|
+
|
13
13
|
if File.exists?("config/mongoid.yml")
|
14
14
|
::Mongoid.load!("config/mongoid.yml")
|
15
15
|
else
|
data/lib/khronos/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
data/spec/tmp/scheduler.db
CHANGED
Binary file
|
data/spec/tmp/sqlite3.db
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: khronos
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.2.pre1
|
5
|
+
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Endel Dreyer
|
@@ -208,9 +208,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
208
208
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
209
209
|
none: false
|
210
210
|
requirements:
|
211
|
-
- - ! '
|
211
|
+
- - ! '>'
|
212
212
|
- !ruby/object:Gem::Version
|
213
|
-
version:
|
213
|
+
version: 1.3.1
|
214
214
|
requirements: []
|
215
215
|
rubyforge_project:
|
216
216
|
rubygems_version: 1.8.24
|