Skip to content

Commit

Permalink
fix model.update(), change to ISO dates
Browse files Browse the repository at this point in the history
  • Loading branch information
tysonrm committed Nov 22, 2022
1 parent ce933a5 commit 44bb88a
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 49 deletions.
2 changes: 1 addition & 1 deletion src/adapters/controllers/delete-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function deleteModelFactory (removeModel) {
return {
headers: {
'Content-Type': 'application/json',
'Last-Modified': new Date().toUTCString()
'Last-Modified': new Date().toISOString()
},
statusCode: 201,
body: { modelId: model.id }
Expand Down
2 changes: 1 addition & 1 deletion src/adapters/controllers/live-rollout.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function makeLiveRollout (hotDeploy) {
return {
headers: {
'Content-Type': 'application/json',
'Last-Modified': new Date().toUTCString()
'Last-Modified': new Date().toISOString()
},
statusCode: 200,
body: { result }
Expand Down
2 changes: 1 addition & 1 deletion src/adapters/controllers/live-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function makeLiveUpdate (hotReload) {
return {
headers: {
'Content-Type': 'application/json',
'Last-Modified': new Date().toUTCString()
'Last-Modified': new Date().toISOString()
},
statusCode: 200,
body: { fn: liveUpdate.name, result }
Expand Down
2 changes: 1 addition & 1 deletion src/adapters/controllers/patch-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function patchModelFactory (editModel) {
return {
headers: {
'Content-Type': 'application/json',
'Last-Modified': new Date().toUTCString()
'Last-Modified': new Date().toISOString()
},
statusCode: 201,
body: { modelId: model.id }
Expand Down
4 changes: 2 additions & 2 deletions src/adapters/controllers/post-invoke-port.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function anyInvokePortFactory (invokePort) {
return {
headers: {
'Content-Type': 'application/json',
'Last-Modified': new Date().toUTCString()
'Last-Modified': new Date().toISOString()
},
statusCode: 201,
body: { ...result }
Expand All @@ -38,4 +38,4 @@ export default function anyInvokePortFactory (invokePort) {
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/adapters/controllers/post-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function postModelFactory (createModel) {
return {
headers: {
'Content-Type': 'application/json',
'Last-Modified': new Date().toUTCString()
'Last-Modified': new Date().toISOString()
},
statusCode: 201,
body: { modelId: model.id }
Expand Down
17 changes: 8 additions & 9 deletions src/domain/make-ports.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const TIMEOUTSECONDS = 10
const MAXRETRY = 5

function getTimerArgs (args = null) {
const timerArg = { calledByTimer: new Date().toUTCString() }
const timerArg = { calledByTimer: new Date().toISOString() }
if (args) return [...args, timerArg]
return [timerArg]
}
Expand Down Expand Up @@ -155,7 +155,7 @@ async function updatePortFlow (model, port) {
const updateModel = this.equals(model) ? model : this
return updateModel.update(
{
[updateModel.getKey('portFlow')]: [...updateModel.getPortFlow(), port]
[updateModel.getKey('portFlow')]: [...this.getPortFlow(), port]
},
false
)
Expand Down Expand Up @@ -189,13 +189,10 @@ export default function makePorts (ports, adapters, broker, datasource) {
const portConf = ports[port]
const disabled = portConf.disabled || !adapters[port]

// Listen for event that will invoke this port
const rememberPort = addPortListener(
portName,
portConf,
broker,
datasource
)
// dont listen on a disabled port
const rememberPort = disabled
? false
: addPortListener(portName, portConf, broker, datasource)

/**
*
Expand Down Expand Up @@ -264,7 +261,9 @@ export default function makePorts (ports, adapters, broker, datasource) {
// check if the port defines breaker thresholds
const thresholds = portConf.circuitBreaker

// call port without breaker (normal for inbound)
if (!thresholds) return portFn.apply(this, args)

/**
* the circuit breaker instance
* @type {import('./circuit-breaker').breaker}
Expand Down
2 changes: 1 addition & 1 deletion src/domain/mixins.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const toSymbol = keyMap => o => {
* @param {"utc"|"iso"} format
*/
export const fromTimestamp = (timestamps, format = 'utc') => o => {
const formats = { utc: 'toUTCString', iso: 'toISOString' }
const formats = { utc: 'toISOString', iso: 'toISOString' }
const fn = formats[format]

if (!fn) {
Expand Down
23 changes: 5 additions & 18 deletions src/domain/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,22 +263,20 @@ const Model = (() => {

/**
* Concurrency strategy is to merge changes with
* last saved copy; so {@link changes} should include
* zthe current instance; so {@link changes} should include
* only the subset of properties that are changing.
* Concomitant strategy is to use `Symbol`s to
* avoid conflict, which requires a custom
* avoid conflict, which may require a custom
* {@link Serializer} for network and storage
* transmission. If conflict does occur , last
* handling. If conflict does occur, last
* one in wins.
*
* @param {object} changes - object containing updated props
* @param {boolean} validate - run validation by default
* @returns {Promise<Model>}
*/
async update (changes, validate = true) {
const lastsaved = datasource.findSync(this[ID]) || {}
const mergedata = { ...lastsaved, ...this }
const validated = validateUpdates(mergedata, changes, validate)
const validated = validateUpdates(this, changes, validate)
const timestamp = { ...validated, [UPDATETIME]: Date.now() }

await datasource.save(this[ID], timestamp)
Expand All @@ -291,18 +289,7 @@ const Model = (() => {
/**
* Synchronous version of {@link Model.update}.
* Only updates cache. External storage is
* not updated and no event is sent.
*
* Useful for:
* - immediate cache update
* - controlling when/if event is sent
* - calling external storage with custom adapter
*
* Consider situations in which the point is not
* to persist data, but to share it with other
* application components, as is done in workflow
* or between local related model threads, which
* use shared memory.
* not updated
*
* @param {*} changes
* @param {boolean} validate
Expand Down
9 changes: 2 additions & 7 deletions src/domain/thread-pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ export class ThreadPool extends EventEmitter {
errorRateTolerance: this.errorRateThreshold(),
errors: this.errorCount(),
deployments: this.deploymentCount(),
since: new Date(this.startTime).toUTCString()
since: new Date(this.startTime).toISOString()
}
}

Expand Down Expand Up @@ -751,12 +751,7 @@ const ThreadPoolFactory = (() => {

const facade = {
async runJob (jobName, jobData, modelName) {
return getPool(poolName, options).runJob(
jobName,
jobData,
modelName,

)
return getPool(poolName, options).runJob(jobName, jobData, modelName)
},
status () {
return getPool(poolName, options).status()
Expand Down
2 changes: 1 addition & 1 deletion wasm/assembly/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export function portEx (keys: string[], vals: string[]): void {
}

export function onUpdate (keys: string[], vals: string[]): string[][] {
return [['updatedByWasm', new Date(Date.now()).toUTCString()]]
return [['updatedByWasm', new Date(Date.now()).toISOString()]]
}

export function onDelete (keys: string[], vals: string[]): i8 {
Expand Down
2 changes: 1 addition & 1 deletion wasm/build/optimized.wasm.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions wasm/build/optimized.wat
Original file line number Diff line number Diff line change
Expand Up @@ -4428,7 +4428,7 @@
call $~lib/builtins/abort
unreachable
)
(func $~lib/date/Date#toUTCString (param $0 i32) (result i32)
(func $~lib/date/Date#toISOString (param $0 i32) (result i32)
(local $1 i32)
(local $2 i32)
(local $3 i64)
Expand Down Expand Up @@ -5113,7 +5113,7 @@
local.get $2
i32.const 1
local.get $6
call $~lib/date/Date#toUTCString
call $~lib/date/Date#toISOString
call $~lib/array/Array<~lib/string/String>#__uset
local.get $3
i32.const 0
Expand Down
2 changes: 1 addition & 1 deletion wasm/build/untouched.wasm.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions wasm/build/untouched.wat
Original file line number Diff line number Diff line change
Expand Up @@ -7530,7 +7530,7 @@
global.set $~lib/memory/__stack_pointer
local.get $2
)
(func $~lib/date/Date#toUTCString (param $0 i32) (result i32)
(func $~lib/date/Date#toISOString (param $0 i32) (result i32)
(local $1 i32)
(local $2 i32)
(local $3 i32)
Expand Down Expand Up @@ -7820,7 +7820,7 @@
local.get $6
i32.store offset=16
local.get $6
call $~lib/date/Date#toUTCString
call $~lib/date/Date#toISOString
call $~lib/array/Array<~lib/string/String>#__uset
local.get $4
call $~lib/array/Array<~lib/array/Array<~lib/string/String>>#__uset
Expand Down

0 comments on commit 44bb88a

Please sign in to comment.