gh-archive 0.8 → 0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gh-archive.rb +44 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 498649edc20ceb260d6468cd7e9ff46781e148205c17cc2c6dd65cd8c7258e8f
|
4
|
+
data.tar.gz: 6e14d05254a7dcddc3a5afdf1c5e749602fdffc508df70dd1a01ebc97642a78c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b3156cdeec56577f61961b53c5552670534aaba0de3391daba5a99afc23fd09deb79da47879e2fc326eae4e85bbb180c41ca170540f67aa428c73571e443fad
|
7
|
+
data.tar.gz: 8129e09a30fd7abe02066ff890dcbd4d48f6965156f92d92582880883a11e508f397358aa39265fc65e7152c2e8204623a417c8689d3096c34e70df411e092f2
|
data/lib/gh-archive.rb
CHANGED
@@ -56,9 +56,16 @@ class GHAProvider
|
|
56
56
|
@includes = {}
|
57
57
|
@excludes = {}
|
58
58
|
|
59
|
+
@checkpoint_name = nil
|
59
60
|
@use_json = true
|
60
61
|
end
|
61
62
|
|
63
|
+
def use_checkpoint(filename)
|
64
|
+
@checkpoint_name = filename
|
65
|
+
|
66
|
+
return self
|
67
|
+
end
|
68
|
+
|
62
69
|
def parse_events
|
63
70
|
@use_json = false
|
64
71
|
|
@@ -67,7 +74,10 @@ class GHAProvider
|
|
67
74
|
|
68
75
|
def logger=(logger)
|
69
76
|
@logger = logger
|
77
|
+
|
78
|
+
return self
|
70
79
|
end
|
80
|
+
alias :use_logger :logger=
|
71
81
|
|
72
82
|
def get(date)
|
73
83
|
raise "Not implemented"
|
@@ -94,6 +104,16 @@ class GHAProvider
|
|
94
104
|
def each(from = Time.gm(2015, 1, 1), to = Time.now)
|
95
105
|
exceptions = []
|
96
106
|
|
107
|
+
if @checkpoint_name && FileTest.exist?(@checkpoint_name)
|
108
|
+
# Note that this throws an exception if the file is not readable. This is the intended behavior.
|
109
|
+
# As opposed to that, failing to save the checkpoint information just results in a warning on the log.
|
110
|
+
loaded_from = Marshal.load(File.read(@checkpoint_name))
|
111
|
+
raise "The loaded checkpoint (#{loaded_from}) occurs before the current from date (#{from})" if loaded_from < from
|
112
|
+
|
113
|
+
@logger.info("Valid checkpoint loaded. Restored execution from #{loaded_from}.")
|
114
|
+
from = loaded_from
|
115
|
+
end
|
116
|
+
|
97
117
|
self.each_time(from, to) do |current_time|
|
98
118
|
events = []
|
99
119
|
begin
|
@@ -107,6 +127,18 @@ class GHAProvider
|
|
107
127
|
next
|
108
128
|
end
|
109
129
|
|
130
|
+
if @checkpoint_name
|
131
|
+
begin
|
132
|
+
File.open(@checkpoint_name, "wb") do |f|
|
133
|
+
f.write(Marshal.dump(current_time))
|
134
|
+
end
|
135
|
+
rescue
|
136
|
+
@logger.warn(
|
137
|
+
"Unable to save the checkpoint at the specified location (#{File.expand_path(@checkpoint_name)})."
|
138
|
+
)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
110
142
|
events.each do |event|
|
111
143
|
skip = false
|
112
144
|
@includes.each do |key, value|
|
@@ -131,6 +163,18 @@ class GHAProvider
|
|
131
163
|
GC.start
|
132
164
|
end
|
133
165
|
|
166
|
+
if @checkpoint_name
|
167
|
+
begin
|
168
|
+
File.open(@checkpoint_name, "wb") do |f|
|
169
|
+
f.write(Marshal.dump(to))
|
170
|
+
end
|
171
|
+
rescue
|
172
|
+
@logger.warn(
|
173
|
+
"Unable to save the checkpoint at the specified location (#{File.expand_path(@checkpoint_name)})."
|
174
|
+
)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
134
178
|
return exceptions
|
135
179
|
end
|
136
180
|
|