vaccination-characteristics 1.1.1 → 1.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
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 77219c35be2f1451bd17ca3364270343bf888067de19a5d2293f82e9ae1721b4
|
|
4
|
+
data.tar.gz: 58b72e60aba221f8f17e91d37386036374a436ae52c2e94841c0456bf450c154
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a797ec42d1d50ad751774187a8018cd5e900669e91811485aa0a954aa913cc450535420216b3c41123922c36cd6fdad3928b9efd641625ef431e50ee24b9a463
|
|
7
|
+
data.tar.gz: 2fb66baacfb77d4d67920c3b0ec83e5d81d05ca1642b00d37918fc0738ef812f3299196bbda72fa49405b3ccaa4046df5fcb2ad5a366c3cd14e198155d9b4822
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module VaccinationCharacteristics
|
|
4
|
+
class VersionWatcher
|
|
5
|
+
attr_reader :current_version_hash
|
|
6
|
+
|
|
7
|
+
def initialize(fetch_latest_version_hash:, polling_interval:, on_update:, on_error: nil)
|
|
8
|
+
raise ArgumentError, "polling_interval must be positive" unless polling_interval.positive?
|
|
9
|
+
raise ArgumentError, "on_update must respond to #call" unless on_update.respond_to?(:call)
|
|
10
|
+
raise ArgumentError, "on_error must respond to #call" unless on_error.nil? || on_error.respond_to?(:call)
|
|
11
|
+
|
|
12
|
+
@fetch_latest_version_hash = fetch_latest_version_hash
|
|
13
|
+
@polling_interval = polling_interval
|
|
14
|
+
@on_update = on_update
|
|
15
|
+
@on_error = on_error
|
|
16
|
+
@current_version_hash = @fetch_latest_version_hash.call
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def start
|
|
20
|
+
@thread = Thread.new do
|
|
21
|
+
loop do
|
|
22
|
+
sleep(@polling_interval)
|
|
23
|
+
check_for_update
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
self
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def stop
|
|
31
|
+
@thread&.kill
|
|
32
|
+
@thread&.join
|
|
33
|
+
|
|
34
|
+
self
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def check_for_update
|
|
38
|
+
latest_version_hash = @fetch_latest_version_hash.call
|
|
39
|
+
|
|
40
|
+
return if latest_version_hash == @current_version_hash
|
|
41
|
+
|
|
42
|
+
@on_update.call(latest_version_hash)
|
|
43
|
+
|
|
44
|
+
@current_version_hash = latest_version_hash
|
|
45
|
+
rescue StandardError => e
|
|
46
|
+
@on_error&.call(e)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def running?
|
|
50
|
+
@thread&.alive? || false
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
require_relative "vaccination_characteristics/version"
|
|
4
4
|
require_relative "vaccination_characteristics/VaccinationCharacteristicsDatabase_pb"
|
|
5
5
|
require_relative "vaccination_characteristics/repository"
|
|
6
|
+
require_relative "vaccination_characteristics/version_watcher"
|
|
6
7
|
require "net/http"
|
|
7
8
|
require "json"
|
|
8
9
|
require "ostruct"
|
|
@@ -56,6 +57,15 @@ module VaccinationCharacteristics
|
|
|
56
57
|
hash
|
|
57
58
|
end
|
|
58
59
|
|
|
60
|
+
def watch_latest_version(cdn_uri: DEFAULT_CDN_URI, polling_interval: 60, on_update:, on_error: nil)
|
|
61
|
+
VersionWatcher.new(
|
|
62
|
+
fetch_latest_version_hash: -> { fetch_latest_version_hash(cdn_uri:) },
|
|
63
|
+
polling_interval:,
|
|
64
|
+
on_update:,
|
|
65
|
+
on_error:
|
|
66
|
+
).start
|
|
67
|
+
end
|
|
68
|
+
|
|
59
69
|
def load_from_file(path)
|
|
60
70
|
Database.new(VaccinationCharacteristicsDatabase.decode(File.read(path)))
|
|
61
71
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: vaccination-characteristics
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Syadem
|
|
@@ -60,6 +60,7 @@ files:
|
|
|
60
60
|
- lib/vaccination_characteristics/repositories/condition_repository.rb
|
|
61
61
|
- lib/vaccination_characteristics/repository.rb
|
|
62
62
|
- lib/vaccination_characteristics/version.rb
|
|
63
|
+
- lib/vaccination_characteristics/version_watcher.rb
|
|
63
64
|
homepage: https://docs.nuva.mesvaccins.net
|
|
64
65
|
licenses:
|
|
65
66
|
- MIT
|