PeerTube/server/lib/jobs/http-request-job-scheduler/http-request-broadcast-hand...

37 lines
852 B
TypeScript
Raw Normal View History

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