gh-archive 0.8 → 0.9

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/gh-archive.rb +44 -0
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a4a9b89fb02620499e8b51f5c5e4ba34d0f3bc8b8f3ae4e2e69cba1e027bdb49
4
- data.tar.gz: 6b707eb1bcb37b8a9b03ce36a2d4304e6760def0cc139ffad748a1596046f82f
3
+ metadata.gz: 498649edc20ceb260d6468cd7e9ff46781e148205c17cc2c6dd65cd8c7258e8f
4
+ data.tar.gz: 6e14d05254a7dcddc3a5afdf1c5e749602fdffc508df70dd1a01ebc97642a78c
5
5
  SHA512:
6
- metadata.gz: '0975e354e028e768fb5bc4c17c19cddbc44b706394f60d8e22a64537a34342965bb98fa00365c329c30d189729dadba271ec6b101ff86593affef7e1d34848b3'
7
- data.tar.gz: 95935fb3c27841760a68696c832e02108940f9eef535f5ed89afea9613a7988c622f2649f3feb77b22706250a30cfba30b5f36f2ada617f532e86a0426e052ce
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gh-archive
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.8'
4
+ version: '0.9'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simone Scalabrino