kronos-ruby 0.2.1.alpha.10 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 94065dd5befb97c9a910ef8beb81af2986b63f1b
4
- data.tar.gz: bc29df98662ec85c9830b9db4e2e3cee12a5e8c3
3
+ metadata.gz: 138131adeba7fb2ccff6d4f4b83eb3fca66940c7
4
+ data.tar.gz: 9f7c9106549b7c4ed245f9a7b8d9c00475716365
5
5
  SHA512:
6
- metadata.gz: 5f49278e16b63184f277d3c7636ae47c7d6c0fedb2a948a48c4509fd2addd881eb2a8082df0fa094209180b477aaf75e7d9218f3cc710fe0978d9a272b917422
7
- data.tar.gz: aa21e234ea82b1c543c939afc1ca81a85f96e7fb80aef542b78414ef50185ffa23af99edfd710c7b17adac8f79fd2f1cbd013867030fc74d6f2d500ec4bf38a1
6
+ metadata.gz: bcf5c19cab28bc0b8d69a18358888f27f428e39af639cbc454a7fc2ff1d2f89b7a2debdc8cbcd35b4359816bebf47f131ea596b27ebee10874f0206c9be96946
7
+ data.tar.gz: 811141eff3ac9afbc5ad8ce0b34981378543a6a7b2c29a04a617877c84fae6fa4e526b0c88caaf4f7611bb3b2bf91f1006becbd396111c9932e84b36e5417b8d
data/README.md CHANGED
@@ -12,7 +12,7 @@ This project allows you to use a scheduler with well defined concepts of runners
12
12
  Add this line to your application's Gemfile:
13
13
 
14
14
  ```ruby
15
- gem 'kronos-ruby', require: ['kronos']
15
+ gem 'kronos-ruby'
16
16
  ```
17
17
 
18
18
  And then execute:
@@ -47,15 +47,6 @@ To view Krono's web dashboard, simply mount it into your Rack stack:
47
47
  mount Kronos::Web::App, at: '/kronos-dashboard'
48
48
  ```
49
49
 
50
- If you want to protect Kronos dashboard, try using `Rack::Auth::Basic`:
51
- ```ruby
52
- protected_kronos = Rack::Auth::Basic.new(Kronos::Web::App) do |username, password|
53
- # Check if username/password tuple is valid
54
- end
55
-
56
- mount protected_kronos, at: '/kronos-dashboard'
57
- ```
58
-
59
50
  ## Developing
60
51
  - Clone this repository
61
52
  - Run `bin/setup` to install dependencies
data/lib/kronos.rb CHANGED
@@ -4,7 +4,6 @@ require 'concurrent'
4
4
  require 'chronic'
5
5
  require 'erb'
6
6
  require 'ostruct'
7
- require 'forwardable'
8
7
 
9
8
  require 'kronos/config_agent'
10
9
  require 'kronos/dependencies'
@@ -24,7 +24,6 @@ module Kronos
24
24
  def initialize(tasks, dependencies)
25
25
  @tasks = tasks
26
26
  @dependencies = dependencies
27
- @lock_manager = LockManager.new(dependencies.storage)
28
27
  end
29
28
 
30
29
  def start
@@ -67,10 +66,9 @@ module Kronos
67
66
 
68
67
  # rubocop:disable RescueException
69
68
  def run_task(task)
70
- task_id = task.id
71
- @lock_manager.lock_and_execute(task_id) { raw_execute_task(task) }
69
+ raw_execute_task(task)
72
70
  rescue ::Exception => error
73
- register_task_failure(task_id, error)
71
+ register_task_failure(task.id, error)
74
72
  end
75
73
  # rubocop:enable
76
74
 
@@ -111,5 +109,3 @@ module Kronos
111
109
  end
112
110
  end
113
111
  end
114
-
115
- require 'kronos/runner/synchronous/lock_manager'
@@ -9,7 +9,6 @@ module Kronos
9
9
  def initialize
10
10
  @scheduled_tasks = []
11
11
  @reports = []
12
- @locks = {}
13
12
  end
14
13
 
15
14
  def schedule(scheduled_task)
@@ -49,24 +48,6 @@ module Kronos
49
48
  def remove_reports_for(id)
50
49
  @reports.reject! { |report| report.task_id == id }
51
50
  end
52
-
53
- def locked_task?(task_id)
54
- @locks.key?(task_id)
55
- end
56
-
57
- def lock_task(task_id)
58
- SecureRandom.uuid.tap do |lock_id|
59
- @locks[task_id] = lock_id
60
- end
61
- end
62
-
63
- def check_lock(task_id, lock_id)
64
- @locks[task_id] == lock_id
65
- end
66
-
67
- def release_lock(task_id)
68
- @locks.delete(task_id)
69
- end
70
51
  end
71
52
  end
72
53
  end
@@ -2,16 +2,13 @@
2
2
 
3
3
  require 'kronos/storage/mongo/model/scheduled_task_model'
4
4
  require 'kronos/storage/mongo/model/report_model'
5
- require 'kronos/storage/mongo/model/lock_model'
6
5
 
7
6
  module Kronos
8
7
  module Storage
9
8
  # :reek:UtilityFunction:
10
- # :reek:TooManyMethods:
11
9
  class MongoDb
12
10
  SHEDULED_TASK_MODEL = Mongo::Model::ScheduledTaskModel
13
11
  REPORT_MODEL = Mongo::Model::ReportModel
14
- LOCK_MODEL = Mongo::Model::LockModel
15
12
 
16
13
  def scheduled_tasks
17
14
  # Returns all current Kronos::ScheduledTask, resolved or pending
@@ -56,31 +53,13 @@ module Kronos
56
53
  query.exists? && query.first.next_run > Time.now
57
54
  end
58
55
 
59
- def locked_task?(task_id)
60
- LOCK_MODEL.where(task_id: task_id).exists?
61
- end
62
-
63
- def lock_task(task_id)
64
- SecureRandom.uuid.tap do |lock_id|
65
- LOCK_MODEL.create(task_id: task_id, value: lock_id)
66
- end
67
- end
68
-
69
- def check_lock(task_id, lock_id)
70
- LOCK_MODEL.where(task_id: task_id, value: lock_id).exists?
71
- end
72
-
73
- def release_lock(task_id)
74
- LOCK_MODEL.where(task_id: task_id).destroy_all
75
- end
76
-
77
56
  private
78
57
 
79
58
  def mount_report(report_model)
80
59
  case report_model.status
81
- when Kronos::Report::STATUSES[:success]
60
+ when 0
82
61
  mount_success_report(report_model)
83
- when Kronos::Report::STATUSES[:failure]
62
+ when 1
84
63
  mount_failure_report(report_model)
85
64
  end
86
65
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kronos-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1.alpha.10
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriel Teles
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-27 00:00:00.000000000 Z
11
+ date: 2017-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -255,11 +255,9 @@ files:
255
255
  - lib/kronos/runner.rb
256
256
  - lib/kronos/runner/asynchronous.rb
257
257
  - lib/kronos/runner/synchronous.rb
258
- - lib/kronos/runner/synchronous/lock_manager.rb
259
258
  - lib/kronos/scheduled_task.rb
260
259
  - lib/kronos/storage.rb
261
260
  - lib/kronos/storage/in_memory.rb
262
- - lib/kronos/storage/mongo/model/lock_model.rb
263
261
  - lib/kronos/storage/mongo/model/report_model.rb
264
262
  - lib/kronos/storage/mongo/model/scheduled_task_model.rb
265
263
  - lib/kronos/storage/mongo_db.rb
@@ -283,12 +281,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
283
281
  version: '0'
284
282
  required_rubygems_version: !ruby/object:Gem::Requirement
285
283
  requirements:
286
- - - ">"
284
+ - - ">="
287
285
  - !ruby/object:Gem::Version
288
- version: 1.3.1
286
+ version: '0'
289
287
  requirements: []
290
288
  rubyforge_project:
291
- rubygems_version: 2.6.13
289
+ rubygems_version: 2.4.8
292
290
  signing_key:
293
291
  specification_version: 4
294
292
  summary: Persistent cron jobs manager
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Kronos
4
- module Runner
5
- class Synchronous
6
- class LockManager
7
- extend Forwardable
8
-
9
- def initialize(storage)
10
- @storage = storage
11
- end
12
-
13
- def lock_and_execute(task_id)
14
- return if locked_task?(task_id)
15
- lock_id = lock_task(task_id)
16
- return unless check_lock(task_id, lock_id)
17
- yield
18
- ensure
19
- release_lock(task_id)
20
- end
21
-
22
- def_delegator :@storage, :locked_task?, :locked_task?
23
- def_delegator :@storage, :lock_task, :lock_task
24
- def_delegator :@storage, :check_lock, :check_lock
25
- def_delegator :@storage, :release_lock, :release_lock
26
- end
27
- end
28
- end
29
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'mongoid'
4
-
5
- module Kronos
6
- module Storage
7
- module Mongo
8
- module Model
9
- class LockModel
10
- include Mongoid::Document
11
- store_in collection: :kronos_locks
12
-
13
- field :task_id, type: Symbol
14
- field :value, type: String
15
- end
16
- end
17
- end
18
- end
19
- end