-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DDEX indexer -> publisher talking (#7452)
- Loading branch information
1 parent
109be52
commit 9f169e7
Showing
8 changed files
with
202 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package constants | ||
|
||
const ( | ||
DeliveryStatusError = "error" | ||
DeliveryStatusRejected = "rejected" | ||
DeliveryStatusValidating = "validating" | ||
DeliveryStatusAwaitingPublishing = "awaiting_publishing" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import mongoose from 'mongoose' | ||
|
||
// Releases that parsed from indexed DDEX deliveries, awaiting publishing | ||
const parsedSchema = new mongoose.Schema({ | ||
delivery_id: String, | ||
entity: String, | ||
publish_date: Date, | ||
}) | ||
|
||
const Parsed = mongoose.model('Parsed', parsedSchema, 'parsed') | ||
|
||
export default Parsed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import mongoose from 'mongoose' | ||
|
||
// DDEX releases that have been published | ||
const publishedSchema = new mongoose.Schema({ | ||
delivery_id: String, | ||
entity: String, | ||
publish_date: Date, | ||
track_id: String, | ||
}) | ||
|
||
const Published = mongoose.model('Published', publishedSchema, 'published') | ||
|
||
export default Published |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import mongoose from 'mongoose' | ||
import Parsed from '../models/parsed' | ||
import Published from '../models/published' | ||
|
||
export const publishReleases = async () => { | ||
// eslint-disable-next-line no-constant-condition | ||
while (true) { | ||
const currentDate = new Date() | ||
|
||
const session = await mongoose.startSession() | ||
session.startTransaction() | ||
|
||
try { | ||
const documents = await Parsed.find({ | ||
publish_date: { $lte: currentDate }, | ||
}).session(session) | ||
|
||
for (const doc of documents) { | ||
// TODO publish release using SDK | ||
|
||
// Move document to 'published' collection | ||
const publishedData = { | ||
...doc.toObject(), | ||
track_id: 'todo', | ||
} | ||
const publishedDoc = new Published(publishedData) | ||
await publishedDoc.save({ session }) | ||
await Parsed.deleteOne({ _id: doc._id }).session(session) | ||
// TODO update indexed delivery_status to 'published' | ||
console.log('Published release: ', publishedData) | ||
} | ||
|
||
await session.commitTransaction() | ||
} catch (error) { | ||
console.error('Error publishing release, rolling back.', error) | ||
await session.abortTransaction() | ||
} finally { | ||
session.endSession() | ||
} | ||
|
||
// 10 seconds | ||
await new Promise((resolve) => setTimeout(resolve, 10000)) | ||
} | ||
} |