fix: preserve first-task completion delivery
This commit is contained in:
parent
d0780a72a7
commit
37e919f43f
|
|
@ -102,6 +102,7 @@
|
||||||
function completeOutcome() {
|
function completeOutcome() {
|
||||||
if (state() !== 'coaching') return false;
|
if (state() !== 'coaching') return false;
|
||||||
store('complete');
|
store('complete');
|
||||||
|
options.eventTarget?.dispatchEvent?.(new CustomEvent('stackchain:first-task-complete'));
|
||||||
renderCoach();
|
renderCoach();
|
||||||
if (options.receipt) {
|
if (options.receipt) {
|
||||||
options.receipt.hidden = false;
|
options.receipt.hidden = false;
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@ function createTodaySync({ storage, getLogin, fetchJson, onRemoteIds, onRemotePl
|
||||||
let discardedCount = 0;
|
let discardedCount = 0;
|
||||||
let recoveryNotice = { discarded: 0, until: 0 };
|
let recoveryNotice = { discarded: 0, until: 0 };
|
||||||
const knownOperationKeys = new Set();
|
const knownOperationKeys = new Set();
|
||||||
const operationRecordKeys = new Map();
|
|
||||||
|
|
||||||
function cancelRetry() {
|
function cancelRetry() {
|
||||||
if (retryTimer !== null) clearTimer?.(retryTimer);
|
if (retryTimer !== null) clearTimer?.(retryTimer);
|
||||||
|
|
@ -138,7 +137,6 @@ function createTodaySync({ storage, getLogin, fetchJson, onRemoteIds, onRemotePl
|
||||||
['add', 'remove', 'move', 'configure', 'rollover', 'activate'].includes(operation.action) &&
|
['add', 'remove', 'move', 'configure', 'rollover', 'activate'].includes(operation.action) &&
|
||||||
typeof operation.item_id === 'string') && Number.isFinite(Number(record.queued_at));
|
typeof operation.item_id === 'string') && Number.isFinite(Number(record.queued_at));
|
||||||
if (valid) operations.forEach((operation, index) => {
|
if (valid) operations.forEach((operation, index) => {
|
||||||
operationRecordKeys.set(operation.operation_id, recordKey);
|
|
||||||
records.push({operation, queued_at:Number(record.queued_at) + index / 1000, recordKey});
|
records.push({operation, queued_at:Number(record.queued_at) + index / 1000, recordKey});
|
||||||
});
|
});
|
||||||
else {
|
else {
|
||||||
|
|
@ -175,12 +173,10 @@ function createTodaySync({ storage, getLogin, fetchJson, onRemoteIds, onRemotePl
|
||||||
function removeOperation(operationId) {
|
function removeOperation(operationId) {
|
||||||
const storageKey = key();
|
const storageKey = key();
|
||||||
if (!storageKey || !storage) return false;
|
if (!storageKey || !storage) return false;
|
||||||
const recordKey = operationRecordKeys.get(operationId) ||
|
const recordKey = storageKey + '.operation.' + encodeURIComponent(operationId);
|
||||||
storageKey + '.operation.' + encodeURIComponent(operationId);
|
|
||||||
try {
|
try {
|
||||||
storage.removeItem(recordKey);
|
storage.removeItem(recordKey);
|
||||||
knownOperationKeys.delete(recordKey);
|
knownOperationKeys.delete(recordKey);
|
||||||
operationRecordKeys.delete(operationId);
|
|
||||||
return true;
|
return true;
|
||||||
} catch (_error) {
|
} catch (_error) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -197,13 +193,11 @@ function createTodaySync({ storage, getLogin, fetchJson, onRemoteIds, onRemotePl
|
||||||
const storageKey = key();
|
const storageKey = key();
|
||||||
if (!storageKey || !storage) return false;
|
if (!storageKey || !storage) return false;
|
||||||
const batched = operations.length > 1;
|
const batched = operations.length > 1;
|
||||||
const recordKey = storageKey + '.operation.' + (batched ? 'batch-' : '') +
|
const recordKey = storageKey + '.operation.' + encodeURIComponent(operations[0].operation_id);
|
||||||
encodeURIComponent(operations[0].operation_id);
|
|
||||||
try {
|
try {
|
||||||
storage.setItem(recordKey, JSON.stringify(batched ?
|
storage.setItem(recordKey, JSON.stringify(batched ?
|
||||||
{operations, queued_at:queuedAt} : {operation:operations[0], queued_at:queuedAt}));
|
{operations, queued_at:queuedAt} : {operation:operations[0], queued_at:queuedAt}));
|
||||||
knownOperationKeys.add(recordKey);
|
knownOperationKeys.add(recordKey);
|
||||||
operations.forEach(operation => operationRecordKeys.set(operation.operation_id, recordKey));
|
|
||||||
coordinator?.notify('today');
|
coordinator?.notify('today');
|
||||||
onStatus?.('pending');
|
onStatus?.('pending');
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -214,7 +214,7 @@ process.stdout.write(JSON.stringify({before,globalProbe,completed,stored:values.
|
||||||
"globalProbe": True,
|
"globalProbe": True,
|
||||||
"completed": True,
|
"completed": True,
|
||||||
"stored": "complete",
|
"stored": "complete",
|
||||||
"dispatched": 0,
|
"dispatched": 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user