使用云功能更新文档属性而不触发onUpdate()

时间:2019-10-25 13:20:45

标签: javascript google-cloud-firestore google-cloud-functions

from gekko import GEKKO import numpy as np import matplotlib.pyplot as plt m = GEKKO() m.time = np.linspace(0,20,41) p = m.MV(value=0, lb=0, ub=100) # Declare MV p.STATUS = 1 # allow optimizer to change p.DCOST = 0.1 # smooth MV response p.DMAX = 10.0 # max move constraint v = m.Var(value=0) sp = np.ones(41)*40 sp[20:] = 60 s = m.Param(value=sp) e = m.CV(value=0) # Declare CV e.STATUS = 1 # add CV to the objective m.options.CV_TYPE = 2 # squared error e.SP = 0 # set point e.TR_INIT = 1 # error trajectory e.TAU = 5 # time constant of trajectory m.Equation(e==s-v) m.Equation(10*v.dt() == -v + 2*p) m.options.IMODE = 6 # control m.solve(disp=False) plt.figure() plt.subplot(2,1,1) plt.plot(m.time,p.value,'b-',label='MV Optimized') plt.legend() plt.ylabel('Input') plt.subplot(2,1,2) plt.plot(m.time,sp,'k-',label='Setpoint') plt.plot(m.time,v.value,'r--',label='CV Response') plt.ylabel('Output') plt.xlabel('Time') plt.legend(loc='best') plt.show() 具有特定值时,我想为文档分配一个新值。我可以执行previousValue,但触发器将再次触发并被循环。

我想在文档更改时创建业务规则,并用新值更新该文档对象,但是我不想再次调用firestore('collection').doc('id').update(newValue)函数。

onUpdate()

是否可以通过在触发export const onScheduleUpdated = functions.firestore .document('units/{unitId}/schedules/{scheduleId}') .onUpdate(async (change, context) => { const previousValue = change.before.data(); const newValue = change.after.data(); if (!newValue) { return; } if (previousValue && previousValue.status === 'inAttendance' && newValue.status === 'answered') { const hour = moment(); const hourSchedule = moment(newValue.endHour); if (hour.diff(hourSchedule, 'minutes') <= 59) { newValue.endHour = moment().toDate(); } /** * If I do it will be in a correct loop? I would like to create business rules within * this function to change the value of the document without triggering the trigger again. */ await firestore.collection('units').doc(context.params.unitId) .collection('schedules').doc(context.params.scheduleId).update(newValue); } }); 函数时将新值分配给文档属性来更新文档,而无需再次触发该触发器?

0 个答案:

没有答案
相关问题