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 CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- khronos (0.1.0)
4
+ khronos (0.1.1)
5
5
  activerecord (~> 3.2.8)
6
6
  girl_friday (~> 0.10.0)
7
7
  json (~> 1.7.5)
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 })
@@ -5,7 +5,6 @@ module Khronos
5
5
  class Scheduler
6
6
 
7
7
  def self.run(schedule, runner=nil)
8
- puts "Khronos::Scheduler#run => #{schedule.inspect}"
9
8
  schedule.update_attributes(:active => false)
10
9
  schedule.save
11
10
  runner.enqueue(schedule) if runner
@@ -39,7 +39,6 @@ module Khronos
39
39
  end
40
40
 
41
41
  def log_schedule!(schedule_log)
42
- puts "Log schedule! #{schedule_log.inspect}"
43
42
  RestClient.post( scheduler_route('/schedule/log'), schedule_log )
44
43
  end
45
44
 
@@ -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
@@ -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 :db do
4
+ namespace :khronos do
5
+ namespace :db do
5
6
 
6
- desc 'Create the database.'
7
- task :create do
8
- adapter = Khronos::Storage::Adapter.get(ENV['KHRONOS_STORAGE'])
9
- if adapter.name =~ /ActiveRecord/
10
- CreateSchedule.up
11
- CreateScheduleLog.up
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
- desc 'Destroy entire database.'
16
- task :drop do
17
- adapter = Khronos::Storage::Adapter.get(ENV['KHRONOS_STORAGE'])
18
- if adapter.name =~ /ActiveRecord/
19
- CreateSchedule.down
20
- CreateScheduleLog.down
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
-
@@ -1,3 +1,3 @@
1
1
  module Khronos
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -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
- puts "status_code => #{last_response.body.inspect}"
128
- #logs = JSON.parse(last_response.body)
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: khronos
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: