services_client_error.tasks.inc in Services Client 7
Same filename and directory in other branches
Queue Runner tasks callbacks.
File
services_client_error/services_client_error.tasks.incView source
<?php
/**
* @file
* Queue Runner tasks callbacks.
*/
/**
* Re-try to send data to remote connection on services client failure.
*
* @param array $data
* Data from queue.
* array('eid' = 9999);
*
* @return bool
* TRUE if updated.
*/
function services_client_error_task_retry_call($data) {
$error = services_client_error_load($data['eid']);
// Error could be deleted by user.
if (empty($error)) {
return TRUE;
}
// Proceed only if error haven't been processed yet.
if ($error['status'] == SC_ERROR_UNPROCESSED) {
$result = services_client_error_retry($error);
// Build log message.
$log = array(
'message' => t('Automatic re-try via queue runner.'),
'eid' => $error['eid'],
);
if (!empty($result['status'])) {
$log['status'] = $result['status'];
}
else {
$log['error_code'] = $result['error_code'];
$log['error_message'] = $result['error_message'];
}
services_client_error_log_save($log);
return $result;
}
// Error has been processed, or overwritten.
return TRUE;
}
/**
* Implements finalize hook to determine queue item state.
*/
function services_client_error_task_finalize($data, $result) {
// Error can't be processed, i.e. it was marked as done, overwritten.
if ($result === TRUE) {
return QUEUERUNNER_STATE_DONE;
}
else {
// If error is recovered, don't re-try
if (isset($result['status']) && $result['status'] == SC_ERROR_COMPLETED) {
return QUEUERUNNER_STATE_DONE;
}
else {
if ($result['retries'] >= $data['retries']) {
$log = array(
'message' => t("Automatic ret-ry failed"),
'eid' => $data['eid'],
'status_change' => SC_ERROR_FAILED,
);
services_client_error_log_save($log);
db_query("UPDATE {services_client_error} SET status = :status WHERE eid = :eid", array(
':eid' => $data['eid'],
':status' => SC_ERROR_FAILED,
))
->execute();
}
}
}
return QUEUERUNNER_STATE_RETRYING;
}
Functions
Name | Description |
---|---|
services_client_error_task_finalize | Implements finalize hook to determine queue item state. |
services_client_error_task_retry_call | Re-try to send data to remote connection on services client failure. |