Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make upload-last script support slack output #84

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/lib/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ const DB_PASSWORD = process.env.DB_PASSWORD || ''
const DB_NAME = process.env.DB_NAME || ''
const CONN_STRING = `mongodb+srv://${DB_USER}:${DB_PASSWORD}@charles-mongo-cluster-ekbll.mongodb.net/${DB_NAME}?retryWrites=true`

async function connect () {
async function connect ({ logSuccess = true }) {
if (mongoose.connection.readyState !== mongoose.STATES.connected) {
return mongoose
.connect(CONN_STRING)
.then(() => {
console.log('- DB Connection Open -')
if (logSuccess) console.log('- DB Connection Open -')
return mongoose
})
}
Expand Down
32 changes: 23 additions & 9 deletions tools/classes/upload-last.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const isEmpty = require('lodash/isEmpty')

program
.option('--use-secondary', 'To use secondary vimeo account')
.option('--slack-output', 'To format output to be send to slack')

program.parse(process.argv)

Expand All @@ -18,28 +19,41 @@ if (options.useSecondary) {
const db = require('../../src/lib/db')
const klass = require('../../src/usecases/class')

function logger () {
if (options.slackOutput) return () => {}
return console.log
}

async function main () {
const vimeoAccountName = options.useSecondary ? 'SECONDARY' : 'PRIMARY'
console.info(`➤ ${vimeoAccountName} VIMEO UPLOAD LAST`.bgBlue.white)
console.info('➤ Connecting DB'.blue)
await db.connect()
logger(`➤ ${vimeoAccountName} VIMEO UPLOAD LAST`.bgBlue.white)
logger('➤ Connecting DB'.blue)
await db.connect({ logSuccess: !options.slackOutput })

console.info('➤ Connecting to Vimeo'.blue)
logger('➤ Connecting to Vimeo'.blue)
const uploadedClasses = await klass.uploadLastClasses()
console.info('✔ Classes upload finished'.green)
logger('✔ Classes upload finished'.green)

return uploadedClasses
// TODO: build return the json for the slack block
return {
uploadedClasses,
vimeoAccountName
}
}

main()
.then(classes => {
if (isEmpty(classes)) {
console.info('🤷 No classes to upload'.yellow)
logger('🤷 No classes to upload'.yellow)
process.exit(0)
}

console.log(`✔ ${classes.length} Classes uploaded`.green)
classes.map(klass => console.table(klass))
logger(`✔ ${classes.length} Classes uploaded`.green)

if (!options.slackOutput) {
classes.map(klass => console.table(klass))
}

process.exit(0)
})
.catch(error => {
Expand Down