1 | 'use strict'
|
2 |
|
3 | const co = require('co')
|
4 | const cli = require('heroku-cli-util')
|
5 |
|
6 | function * run (context, heroku) {
|
7 | const fetcher = require('../lib/fetcher')
|
8 | const psql = require('../lib/psql')
|
9 |
|
10 | const {app, args, flags} = context
|
11 | const {pid, database} = args
|
12 | const {force} = flags
|
13 |
|
14 | let db = yield fetcher(heroku).database(app, database)
|
15 |
|
16 | let query = `
|
17 | SELECT ${force ? 'pg_terminate_backend' : 'pg_cancel_backend'}(${parseInt(pid)});`
|
18 |
|
19 | let output = yield psql.exec(db, query)
|
20 | process.stdout.write(output)
|
21 | }
|
22 |
|
23 | module.exports = {
|
24 | topic: 'pg',
|
25 | command: 'kill',
|
26 | description: 'kill a query',
|
27 | needsApp: true,
|
28 | needsAuth: true,
|
29 | flags: [{name: 'force', char: 'f'}],
|
30 | args: [
|
31 | {name: 'pid'},
|
32 | {name: 'database', optional: true}
|
33 | ],
|
34 | run: cli.command({preauth: true}, co.wrap(run))
|
35 | }
|