khronos 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/README.md +7 -0
- data/lib/khronos/scheduler.rb +0 -1
- data/lib/khronos/server/runner.rb +0 -1
- data/lib/khronos/server/scheduler.rb +16 -1
- data/lib/khronos/tasks/db.rake +17 -16
- data/lib/khronos/version.rb +1 -1
- data/spec/integration/scheduler_server_spec.rb +14 -4
- metadata +1 -1
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -38,6 +38,13 @@ Query for a scheduled task:
|
|
38
38
|
RestClient.get('http://localhost:3000/task', :params => { :context => 'test' })
|
39
39
|
# => "{\"active\":true,\"at\":\"2012-09-15T21:24:56-03:00\",\"context\":\"test\",\"id\":1,\"recurrency\":1,\"task_url\":\"http://myapp.com/do-something-awesome\"}"
|
40
40
|
|
41
|
+
Delete a scheduled task by query:
|
42
|
+
|
43
|
+
RestClient.delete('http://localhost:3000/task', :params => { :status_code => 404 })
|
44
|
+
# => "{\"deleted\":3}"
|
45
|
+
RestClient.delete('http://localhost:3000/task', :params => { :id => 9 })
|
46
|
+
# => "{\"deleted\":1}"
|
47
|
+
|
41
48
|
Query for logs for tasks that already ran.
|
42
49
|
|
43
50
|
RestClient.get('http://localhost:3000/schedule/logs', :params => { :status_code => 500 })
|
data/lib/khronos/scheduler.rb
CHANGED
@@ -14,7 +14,7 @@ module Khronos
|
|
14
14
|
:name => "Khronos - HTTP Job Scheduler Interface.",
|
15
15
|
:version => Khronos::VERSION,
|
16
16
|
:link => "https://github.com/endel/khronos"
|
17
|
-
}
|
17
|
+
}.to_json
|
18
18
|
end
|
19
19
|
|
20
20
|
# Creates a schedule
|
@@ -90,6 +90,21 @@ module Khronos
|
|
90
90
|
schedule.to_json
|
91
91
|
end
|
92
92
|
|
93
|
+
# Delete a single task by params
|
94
|
+
#
|
95
|
+
# @param [String] context
|
96
|
+
# @param [String] context
|
97
|
+
#
|
98
|
+
# @return [Hash]
|
99
|
+
delete '/task' do
|
100
|
+
if params.empty?
|
101
|
+
return 403, "Too open query. Use '?all=1' to delete all entries."
|
102
|
+
elsif params['all']
|
103
|
+
params = {}
|
104
|
+
end
|
105
|
+
{ :deleted => Storage::Schedule.where(params).delete_all }.to_json
|
106
|
+
end
|
107
|
+
|
93
108
|
# Force a task to be scheduled right now
|
94
109
|
#
|
95
110
|
# @param [Integer] id
|
data/lib/khronos/tasks/db.rake
CHANGED
@@ -1,25 +1,26 @@
|
|
1
1
|
require 'khronos/storage/adapter/activerecord/migrations/schedule'
|
2
2
|
require 'khronos/storage/adapter/activerecord/migrations/schedule_log'
|
3
3
|
|
4
|
-
namespace :
|
4
|
+
namespace :khronos do
|
5
|
+
namespace :db do
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
desc 'Create the database.'
|
8
|
+
task :create do
|
9
|
+
adapter = Khronos::Storage::Adapter.get(ENV['KHRONOS_STORAGE'])
|
10
|
+
if adapter.name =~ /ActiveRecord/
|
11
|
+
CreateSchedule.up
|
12
|
+
CreateScheduleLog.up
|
13
|
+
end
|
12
14
|
end
|
13
|
-
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
desc 'Destroy entire database.'
|
17
|
+
task :drop do
|
18
|
+
adapter = Khronos::Storage::Adapter.get(ENV['KHRONOS_STORAGE'])
|
19
|
+
if adapter.name =~ /ActiveRecord/
|
20
|
+
CreateSchedule.down
|
21
|
+
CreateScheduleLog.down
|
22
|
+
end
|
21
23
|
end
|
22
|
-
end
|
23
24
|
|
25
|
+
end
|
24
26
|
end
|
25
|
-
|
data/lib/khronos/version.rb
CHANGED
@@ -72,6 +72,17 @@ describe Khronos::Server::Scheduler do
|
|
72
72
|
schedule.at.to_i.should == 1.day.from_now.to_i
|
73
73
|
end
|
74
74
|
|
75
|
+
it "should delete a scheduled task" do
|
76
|
+
schedule = FactoryGirl.create(:schedule, {:context => "to-delete"})
|
77
|
+
delete('/task', :id => schedule.id)
|
78
|
+
Khronos::Storage::Schedule.where(:id => schedule.id).length.should == 0
|
79
|
+
|
80
|
+
schedule = FactoryGirl.create(:schedule)
|
81
|
+
delete('/task')
|
82
|
+
last_response.status.should == 403
|
83
|
+
last_response.body.should include("Too open")
|
84
|
+
end
|
85
|
+
|
75
86
|
it "should retrieve a list of schedules by context pattern" do
|
76
87
|
FactoryGirl.create(:schedule, {:context => "namespaced"})
|
77
88
|
FactoryGirl.create(:schedule, {:context => "namespaced:1"})
|
@@ -123,10 +134,9 @@ describe Khronos::Server::Scheduler do
|
|
123
134
|
get('/schedule/logs', {:status_code => 200, :limit => 1})
|
124
135
|
JSON.parse(last_response.body).length.should == 1
|
125
136
|
|
126
|
-
get('/schedule/logs', {:status_code => 500})
|
127
|
-
|
128
|
-
|
129
|
-
#logs.first['schedule_id'].should == 2
|
137
|
+
get('/schedule/logs', {:status_code => 500, :offset => 1})
|
138
|
+
logs = JSON.parse(last_response.body)
|
139
|
+
logs.first['schedule_id'].should == 2
|
130
140
|
end
|
131
141
|
end
|
132
142
|
|