Skip to content

Commit d564a48

Browse files
committed
tick atomically
Signed-off-by: Tobias Gurtzick <[email protected]>
1 parent 05a7fff commit d564a48

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

lib/state.js

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ module.exports = {
6565
}
6666
},
6767

68+
isOwner: function () {
69+
return owner;
70+
},
71+
6872
init: async function (driver, internals, { emptyState, backupState }) {
6973
await driver._createKV(internals.migrationState);
7074
const _schema = await driver._getKV(internals.migrationState, SSTATE);
@@ -149,17 +153,40 @@ module.exports = {
149153
return Promise.resolve();
150154
}
151155

152-
let { value: state } = await driver._getKV(
156+
let state = await driver._getKV(
153157
internals.migrationState,
154158
MSTATE
155159
);
160+
161+
let runOn = state.run_on;
162+
state = state.value;
156163
state = JSON.parse(state);
157-
state.s.date = new Date();
158-
return driver._updateKV(
164+
165+
if (!state.s.ID || state.s.ID !== ID) {
166+
owner = true;
167+
state.s.ID = ID;
168+
}
169+
170+
const d = new Date();
171+
172+
state.s.date = d;
173+
await driver._updateKVC(
159174
internals.migrationState,
160175
MSTATE,
161-
JSON.stringify(state)
176+
JSON.stringify(state),
177+
RUNON,
178+
runOn
162179
);
180+
181+
state = await driver._getKV(internals.migrationState, MSTATE);
182+
183+
runOn = state.run_on;
184+
state = state.value;
185+
state = JSON.parse(state);
186+
187+
if (state.s.ID !== ID) {
188+
owner = false;
189+
}
163190
},
164191

165192
step: async function (driver, step, internals) {

0 commit comments

Comments
 (0)