'use strict'

const getNamespace = require('continuation-local-storage').getNamespace
const Promise = require('bluebird')
const WorkerStopError = require('error-cat/errors/worker-stop-error')

const Ponos = require('../')

/**
 * A simple worker that will publish a message to a queue.
 * @param {object} job Object describing the job.
 * @param {string} job.queue Queue on which the message will be published.
 * @returns {promise} Resolved when the message is put on the queue.
 */
function basicWorker (job) {
  return Promise.try(() => {
    const tid = getNamespace('ponos').get('tid')
    if (!job.message) {
      throw new WorkerStopError('queue', 'message is required. tid:' + tid)
    }
    console.log(`hello world: ${job.message}. tid: ${tid}`)
  })
}

const server = new Ponos.Server({
  tasks: {
    'basic-queue-worker': basicWorker
  },
  events: {
    'basic-event-worker': basicWorker
  }
})

server.start()
  .then(() => { console.log('server started') })
  .catch((err) => { console.error('server error:', err.stack || err.message || err) })

process.on('SIGINT', () => {
  server.stop()
    .then(() => { console.log('server stopped') })
    .catch((err) => { console.error('server error:', err.stack || err.message || err) })
})

@@ -644,17 +644,8 @@
 ror(
-'queue', 
 'mes
@@ -664,21 +664,23 @@
 ired
-.
+', %7B
  tid:
-' +
  tid
+ %7D
 )%0A  

use correct constructor for new errors