wellness-download
A healthcheck for the wellness module, that can be used inpdependently.
The module downloads a file and checks it against an optionally supplied hash value.
Example
Stand-alone Use
'use strict';var wellnessDownload = ; var opts = file_hash: '338ff9861dd251fd21c30f040a5b831d' hash_type: 'md5' req_opts: url: 'https://close5-item-image-production.s3.amazonaws.com/images/'+ '54dedc25f6aa03c55d0005fd_200_200.jpg' ; wellnessDownload;wellnessDownload;
In Clustered Server
'use strict';var wellness = ;var express = ;var app = ;var numCPUs = length;var wellnessDownload = ; var opts = healthCheckUriPath: '/healthcheck' expressApp: app workerTimeOut: 5000 numWorkers: numCPUs; var dl_opts = file_hash: '338ff9861dd251fd21c30f040a5b831c' hash_type: 'md5' req_opts: url: 'https://close5-item-image-production.s3.amazonaws.com/'+ 'images/54dedc25f6aa03c55d0005fd_200_200.jpg' ;wellnessDownload; { wellness; }var cluster = ; if clusterisMaster for var i = 0; i < numCPUs; i++ cluster; wellness; else wellness;
Test the health check
curl -v http://localhost:3000/healthcheck
API
init(opts)
Initialize the wellness-download module with an options object.
Options:
- req_opts: Options for the request module. Any valid request option can go here. The uri or url is required.
- logger: A winston-like logger object (for logging)
- If a hash_type and file_hash are present, the code will compute the hash for the download and compare it to the file_hash using the hash algorithm determined by hash_type.
- hash_type: Any valid hash type for the Node.js crypto Hash class: sha256, md5, sha1, etc. To see all hashes supported, run the following code:
var crypto = console
file_download(cb)
Perform the file download and, optionally, compute the file hash. Return errors, if any, in the callback.