Skip to content

Commit 604cc2a

Browse files
committed
Add comments explaining playbook concept
1 parent 8755708 commit 604cc2a

File tree

3 files changed

+48
-68
lines changed

3 files changed

+48
-68
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
### Usage
2+
3+
```
4+
# fileset.yaml
5+
6+
site: mysite
7+
schedule:
8+
default: master
9+
2020-12-21 08:10:05: master
10+
2021-01-12 08:10:05: feature/takedown
11+
2050-02-12 09:10:05: feature/takedown-2
12+
```

src/server.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,26 @@ const getManifest = async (siteId: string, branchOrRef: string) => {
3030
if (!result) {
3131
return;
3232
}
33+
return result;
3334

34-
// TODO: Allow this to be overwritten.
35-
const now = new Date();
36-
let latestManifest = null;
37-
for (const ttlString in result.schedule) {
38-
const ttlDate = new Date(ttlString);
39-
const isLaterThanManifestDate = now >= ttlDate;
40-
const isLaterThanAllManifests =
41-
!latestManifest || ttlDate >= latestManifest.ttl;
42-
if (isLaterThanManifestDate && isLaterThanAllManifests) {
43-
latestManifest = result.schedule[ttlString];
44-
latestManifest.ttl = ttlDate;
45-
}
46-
}
47-
if (latestManifest) {
48-
return latestManifest;
49-
}
35+
// TODO: Add getPlaybook which can be used for prod serving and TTLs.
36+
// getManifest is only used for staging.
37+
// // TODO: Allow this to be overwritten.
38+
// const now = new Date();
39+
// let latestManifest = null;
40+
// for (const ttlString in result.schedule) {
41+
// const ttlDate = new Date(ttlString);
42+
// const isLaterThanManifestDate = now >= ttlDate;
43+
// const isLaterThanAllManifests =
44+
// !latestManifest || ttlDate >= latestManifest.ttl;
45+
// if (isLaterThanManifestDate && isLaterThanAllManifests) {
46+
// latestManifest = result.schedule[ttlString];
47+
// latestManifest.ttl = ttlDate;
48+
// }
49+
// }
50+
// if (latestManifest) {
51+
// return latestManifest;
52+
// }
5053
};
5154

5255
const parseHostname = (hostname: string) => {

src/upload.ts

Lines changed: 17 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -130,28 +130,10 @@ export async function uploadManifest(
130130
}
131131
}
132132

133-
interface ScheduleItem {
134-
ttl: Date;
135-
ref: string;
136-
paths: Record<string, string>;
137-
}
138-
139-
function createScheduleItem(
140-
manifest: Manifest,
141-
manifestPaths: Record<string, string>,
142-
ttl: Date
143-
) {
144-
return {
145-
ttl: ttl,
146-
ref: manifest.ref,
147-
paths: manifestPaths,
148-
} as ScheduleItem;
149-
}
150-
151133
async function saveManifestEntity(key: entity.Key, data: any) {
152134
const ent = {
153135
key: key,
154-
excludeFromIndexes: ['schedule'],
136+
excludeFromIndexes: ['paths'],
155137
data: data,
156138
};
157139
await datastore.save(ent);
@@ -161,56 +143,39 @@ async function finalize(manifest: Manifest, ttl?: Date) {
161143
const manifestPaths = manifest.toJSON();
162144
const now = new Date();
163145

164-
// Create shortSha mapping.
146+
// Create shortSha mapping for staging.
165147
const key = datastore.key([
166148
'Fileset2Manifest',
167149
`${manifest.site}:ref:${manifest.shortSha}`,
168150
]);
169-
const scheduleItem = createScheduleItem(manifest, manifestPaths, now);
170-
const schedule: Record<string, ScheduleItem> = {};
171-
schedule[now.toString()] = scheduleItem;
172151
await saveManifestEntity(key, {
173152
site: manifest.site,
174153
ref: manifest.ref,
175154
branch: manifest.branch,
176-
schedule: schedule,
155+
paths: manifestPaths,
177156
});
178157

179-
// Create branch mapping.
158+
// Create branch mapping for staging.
180159
if (manifest.branch) {
181160
const branchKey = datastore.key([
182161
'Fileset2Manifest',
183162
`${manifest.site}:branch:${manifest.branch}`,
184163
]);
185-
const branchScheduleItem = createScheduleItem(
186-
manifest,
187-
manifestPaths,
188-
ttl || now
189-
);
190-
const branchSchedule: Record<string, ScheduleItem> = {};
191-
const branchScheduleKey = (ttl || now).toString();
192-
branchSchedule[branchScheduleKey] = branchScheduleItem;
193-
const resp = await datastore.get(branchKey);
194-
let existingData = resp && resp[0];
195-
if (!existingData) {
196-
existingData = {
197-
site: manifest.site,
198-
ref: manifest.ref,
199-
branch: manifest.branch,
200-
schedule: branchSchedule,
201-
};
202-
} else {
203-
// TODO: Clean up past scheduled items here.
204-
existingData.schedule[branchScheduleKey] = branchScheduleItem;
205-
}
206-
console.log(
207-
`TTLs for branch: ${manifest.branch} -> ${Object.keys(
208-
existingData.schedule
209-
)}`
210-
);
211-
await saveManifestEntity(branchKey, existingData);
164+
await saveManifestEntity(branchKey, {
165+
site: manifest.site,
166+
ref: manifest.ref,
167+
branch: manifest.branch,
168+
paths: manifestPaths,
169+
});
212170
}
213171

172+
// TODO: Update the site's playbook and use the playbook for timed launches.
173+
// The playbook should contain copies of all future launches. Each site should only
174+
// have one playbook.
175+
// const routerKey = datastore.key(['Fileset2Router', manifest.site]);
176+
// const router = await datastore.get(routerKey);
177+
// const entity = router && router[0];
178+
214179
console.log(
215180
`Finalized upload for site: ${manifest.site} -> ${manifest.branch} @ ${manifest.shortSha}`
216181
);

0 commit comments

Comments
 (0)