always unlock

pull/26/head
cupcakearmy 5 years ago
parent e8a8ccccd0
commit ea8bf83799
No known key found for this signature in database
GPG Key ID: D28129AE5654D9D9

@ -6,24 +6,24 @@ import handlers, { error, help } from './handlers'
import { Config } from './types' import { Config } from './types'
import { readLock, writeLock, unlock } from './lock' import { readLock, writeLock, unlock } from './lock'
process.on('uncaughtException', err => { process.on('uncaughtException', (err) => {
console.log(err.message) console.log(err.message)
unlock() unlock()
process.exit(1) process.exit(1)
}) })
export const { _: commands, ...flags } = minimist(process.argv.slice(2), { export const { _: commands, ...flags } = minimist(process.argv.slice(2), {
alias: { alias: {
c: 'config', c: 'config',
v: 'version', v: 'version',
h: 'help', h: 'help',
a: 'all', a: 'all',
l: 'location', l: 'location',
b: 'backend', b: 'backend',
d: 'dry-run', d: 'dry-run',
}, },
boolean: ['a', 'd'], boolean: ['a', 'd'],
string: ['l', 'b'], string: ['l', 'b'],
}) })
export const VERSION = '0.18' export const VERSION = '0.18'
@ -32,33 +32,32 @@ export const VERBOSE = flags.verbose
export let config: Config export let config: Config
async function main() { async function main() {
config = init() config = init()
// Don't let 2 instances run on the same config // Don't let 2 instances run on the same config
const lock = readLock() const lock = readLock()
if (lock.running) { if (lock.running) {
console.log('An instance of autorestic is already running for this config file'.red) console.log('An instance of autorestic is already running for this config file'.red)
return return
} }
writeLock({ writeLock({
...lock, ...lock,
running: true, running: true,
}) })
// For dev // For dev
// return await handlers['cron']([], { ...flags, all: true }) // return await handlers['cron']([], { ...flags, all: true })
if (commands.length < 1 || commands[0] === 'help') return help() if (commands.length < 1 || commands[0] === 'help') return help()
const command: string = commands[0] const command: string = commands[0]
const args: string[] = commands.slice(1) const args: string[] = commands.slice(1)
const fn = handlers[command] || error const fn = handlers[command] || error
await fn(args, flags) await fn(args, flags)
unlock()
} }
main()
main().catch((e: Error) => console.error(e.message)) .catch((e: Error) => console.error(e.message))
.finally(unlock)

Loading…
Cancel
Save