PeerTube/server/lib/jobs/http-request-job-scheduler/http-request-unicast-handle...

34 lines
786 B
TypeScript
Raw Normal View History

2017-11-09 10:51:58 -06:00
import { logger } from '../../../helpers'
2017-11-10 10:27:49 -06:00
import { doRequest } from '../../../helpers/requests'
import { HTTPRequestPayload } from './http-request-job-scheduler'
async function process (payload: HTTPRequestPayload, jobId: number) {
logger.info('Processing unicast in job %d.', jobId)
2017-11-09 10:51:58 -06:00
2017-11-10 10:27:49 -06:00
const uri = payload.uris[0]
const options = {
2017-11-14 10:31:26 -06:00
method: 'POST',
2017-11-10 10:27:49 -06:00
uri,
json: payload.body
}
2017-11-09 10:51:58 -06:00
2017-11-10 10:27:49 -06:00
await doRequest(options)
2017-11-09 10:51:58 -06:00
}
function onError (err: Error, jobId: number) {
2017-11-10 10:27:49 -06:00
logger.error('Error when sending request in job %d.', jobId, err)
2017-11-09 10:51:58 -06:00
return Promise.resolve()
}
async function onSuccess (jobId: number) {
2017-11-10 10:27:49 -06:00
logger.info('Job %d is a success.', jobId)
2017-11-09 10:51:58 -06:00
}
// ---------------------------------------------------------------------------
export {
process,
onError,
onSuccess
}