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

37 lines
852 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 broadcast in job %d.', jobId)
2017-11-09 10:51:58 -06:00
2017-11-10 10:27:49 -06:00
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
for (const uri of payload.uris) {
options.uri = uri
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 broadcasting request in job %d.', jobId, err)
2017-11-09 10:51:58 -06:00
return Promise.resolve()
}
2017-11-15 09:28:35 -06:00
function onSuccess (jobId: number) {
2017-11-10 10:27:49 -06:00
logger.info('Job %d is a success.', jobId)
2017-11-15 09:28:35 -06:00
return Promise.resolve()
2017-11-09 10:51:58 -06:00
}
// ---------------------------------------------------------------------------
export {
process,
onError,
onSuccess
}