1.0.13 • Published 11 years ago

docparse-scraper-status-socket v1.0.13

Weekly downloads
2
License
-
Repository
-
Last release
11 years ago

Scraper Status Socket

Allow node.js based scrapers to connect to a status socket so that external services can query the current status of the scraper and check if it is running or stopped.

When a scraper starts up, it registers a new service with seaport using the role scraperStatusSupplierCode. For example the NGrid Electric scraper has the supplierCode NGE so it would register with the role scraperStatusNGE

Then this module will connect to an axon rep socket on the port returned by seaport.

Querying

To query the status of a scraper, get the port of the status socket from seaport and send a status request

var inspect = require('eyespect').inspector();
var config = require('nconf')
var supplierCode = 'NGE'
var seaConfig = config.get('seaport')
var seaHost = seaConfig.host
var seaPort = seaConfig.port
var ports = seaport.connect(seaHost, seaPort)
var role = 'scraperStatus' + supplierCode // eg "scraperStatusNGE"
var scraperStatusSockets = ports.query(role) // an array of services
var scraperSocketService = scraperStatusSockets[0] // use the first one as an example
var scraperSocketHost = scraperSocketService.host
var scraperSocketPort = scraperSocketService.port

var requestSocket = axon.socket('req')
requestSocket.format('json') // all sockets speak json
requestSocket.bind(scraperSocketPort, scraperSocketHost)

// send the message
requestSocket.send('status', function (err, reply) {
  if (err) { //should not happen
    inspect(err, 'error getting status from NGE scraper status socket')
    return
  }
  inspect(reply, 'NGE scraper status reply') // a json object with fields supplierCode & status
})
1.0.13

11 years ago

1.0.12

11 years ago

1.0.11

11 years ago

1.0.10

11 years ago

1.0.9

11 years ago

1.0.8

11 years ago

1.0.7

11 years ago

1.0.6

11 years ago

1.0.4

11 years ago

1.0.3

11 years ago

1.0.2

11 years ago

1.0.0

11 years ago