Skip to content

Commit

Permalink
Merge pull request #158 from calibreapp/create-site-with-agent-settings
Browse files Browse the repository at this point in the history
Create site with agent settings
  • Loading branch information
Michael Dijkstra authored Feb 6, 2020
2 parents 7921ccc + bccec27 commit 96a1c48
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 9 deletions.
16 changes: 14 additions & 2 deletions examples/nodejs/sites/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ const { Site } = require('calibre')

const create = async () => {
const name = 'Calibre'
const location = 'Frankfurt'

const agentSettings = {
location: 'Frankfurt', // location tag
scheduleAnchor: 6,
scheduleInterval: 'every_x_hours' // options: off, daily, hourly, every_x_hours
}

const pages = [
{
name: 'Home',
Expand Down Expand Up @@ -41,8 +47,14 @@ const create = async () => {
connection: 'good3G'
}
]

try {
const site = await Site.create({ name, location, pages, testProfiles })
const site = await Site.create({
name,
agentSettings,
pages,
testProfiles
})

console.log('Created', site)
} catch (e) {
Expand Down
34 changes: 31 additions & 3 deletions src/api/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@ const CREATE_MUTATION = `
name
slug
agentSettings {
location {
identifier
name
shortName
emoji
tag
agents {
ipv4
}
}
scheduleAnchor
scheduleInterval
}
testProfiles {
name
uuid
Expand Down Expand Up @@ -40,14 +55,27 @@ const DELETE_MUTATION = `
}
`

const create = async ({ name, location, pages, testProfiles }) => {
const create = async ({
name,
location,
pages,
testProfiles,
agentSettings
}) => {
// Support deprecated `location` variable
// Location should now be passed as part of agentSettings
const updatedAgentSettings = { ...agentSettings }
if (location) {
updatedAgentSettings.location = location
}

const response = await request({
query: CREATE_MUTATION,
attributes: {
name,
location,
pages,
testProfiles
testProfiles,
agentSettings: updatedAgentSettings
}
})

Expand Down
21 changes: 17 additions & 4 deletions src/cli/site/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,22 @@ const main = async function(args) {
spinner.start()
}

const { name, location, url } = args
const { name, location, url, schedule, interval } = args
const pages = [
{
url,
name: 'Home',
canonical: true
name: 'Home'
}
]

const agentSettings = {
location,
scheduleInterval: schedule,
scheduleAnchor: interval
}

try {
const site = await create({ name, location, pages })
const site = await create({ name, pages, agentSettings })

if (!args.json) {
spinner.succeed(`${site.name} added to Calibre`)
Expand All @@ -48,6 +53,14 @@ module.exports = {
.option('location', {
describe: 'Calibre will monitor from this location'
})
.option('schedule', {
describe:
'Schedule for automated snapshots. One of: hourly, daily, every_x_hours'
})
.option('interval', {
describe:
"Automated snapshot interval. UTC hour of day for 'daily', hour interval for 'every_x_hours'"
})
.option('json', {
describe: 'Return the site attributes as JSON'
})
Expand Down

0 comments on commit 96a1c48

Please sign in to comment.