Skip to content
This repository was archived by the owner on Sep 27, 2021. It is now read-only.

Commit cb5c963

Browse files
committed
saving logs to storj
1 parent 253f313 commit cb5c963

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

worker.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ async function storjSize(path) {
111111

112112
async function cloneUser({ username, lastSynced }) {
113113
// get list of repositories from Github API
114+
let publicLog = '';
115+
114116
const repos = await getRepos({ username });
115117
const reportedRepos = repos.length;
116118

@@ -136,14 +138,17 @@ async function cloneUser({ username, lastSynced }) {
136138
const lastUpdated = new Date(repo.updated_at);
137139

138140
log.info(repo.full_name, { lastUpdated, lastSynced, updated_at: repo.updated_at });
141+
publicLog += `${repo.full_name} ${JSON.stringify({ lastUpdated, lastSynced, updated_at: repo.updated_at })}\n`;
139142

140143
// skip if repository hasn't been updated since last sync
141144
if(lastUpdated < lastSynced) {
145+
publicLog += `repository hasn't been updated since last sync. skipping\n`;
142146
continue;
143147
}
144148

145149
// skip if repository is too big
146150
if(repo.size > 4250000) {
151+
publicLog += `repository is too big (${repo.size}). skipping\n`;
147152
continue;
148153
}
149154

@@ -158,6 +163,7 @@ async function cloneUser({ username, lastSynced }) {
158163

159164
// Create bundle:
160165
log.info(repo.full_name, 'cloning');
166+
publicLog += `cloning\n`;
161167

162168
try {
163169
await execa('git', ['clone', '--mirror', repo.git_url, repoPath]);
@@ -166,11 +172,13 @@ async function cloneUser({ username, lastSynced }) {
166172
});
167173
} catch(err) {
168174
log.info(repo.full_name, 'clone failed');
175+
publicLog += 'clone failed. skipping\n';
169176
continue;
170177
}
171178

172179
// Download zip:
173180
log.info(repo.full_name, 'downloading zip');
181+
publicLog += 'downloading zip\n';
174182

175183
const {data} = await axios.get(`${repo.html_url}/archive/master.zip`, {
176184
responseType: 'stream',
@@ -201,6 +209,8 @@ async function cloneUser({ username, lastSynced }) {
201209
totalUpload += (await fs.stat(repoZipPath)).size;
202210

203211
log.info(repo.full_name, 'cleaning up');
212+
publicLog += 'cleaning up\n';
213+
204214
await execa('rm', [ '-rf', repoBundlePath ]);
205215
await execa('rm', [ '-rf', repoZipPath ]);
206216
await execa('rm', [ '-rf', repoPath ]);
@@ -209,6 +219,13 @@ async function cloneUser({ username, lastSynced }) {
209219
log.info(repo.full_name, 'done');
210220
}
211221

222+
const logPath = `${__dirname}/repos/${username}.log`;
223+
const storjLogPath = `${pathing.encode(username)}.log`;
224+
225+
storageDelta -= await storjSize(storjLogPath);
226+
await storjUpload(logPath, storjLogPath);
227+
storageDelta += (await fs.stat(logPath)).size;
228+
212229
// wait 5 seconds after each user
213230
await new Promise(resolve => setTimeout(resolve, 5000));
214231

0 commit comments

Comments
 (0)