...
If your Delft-FEWS SA does not start up with the system time as T0, you will want to provide (hardcode) the date/tim in the time0 field of the task property file.
Since you are (probably) running a DOS Batch script to call the workflow taskrun, you might want to use some DOS Batch logic to do so. I will provide an example (and files, if this forum allows me to do so) - but this is expertise/knowledge outside Delft-FEWS. DOS Batch scripting is quitte finicky and an art in and of itself. If you know some other low level way of achieving the same result, go for it. If you do want to use the example batch script, you might need to tweak the logic to get the correct datetime format for your application. My example's format is "DD-MM-YYY HH:MM"
Good luck, let me know if you succeeded and what your final approach was...if you can share, the community can benefit as well!
Example taskProperty (template) file, with search_string "TIMEZERO" (taskProperty_template.xml)-----
<code xml>
Code Block |
---|
|
<?xml version="1.0" encoding="UTF-8"?> |
...
<taskProperties xsi:schemaLocation="http://www.wldelft.nl/fews http://fews.wldelft.nl/schemas/version1.0/taskProperties.xsd" xmlns="http://www.wldelft.nl/fews" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> |
...
<description>ImportNOAAGFSdata_scheduled</description> |
...
...
<workflowId>Import_GFS_0.25_Schedule</workflowId> |
...
...
...
...
...
...
<forecastPriority>Normal</forecastPriority> |
...
<makeForcastCurrent>true</makeForcastCurrent> |
...
...
Example DOS Batch script to replace "TIMEZERO" and write to newly created taskProperty.xml)
-----
@ECHO OFF
setlocal enabledelayedexpansion
set rootdirpath=%~dp0
cd %rootdirpath%
rem Derive parametername from filedirpath
for /F
Code Block |
---|
language | bash |
---|
linenumbers | true |
---|
collapse | true |
---|
|
@ECHO OFF
setlocal enabledelayedexpansion
set rootdirpath=%~dp0
cd %rootdirpath%
rem Derive parametername from filedirpath
for /F "tokens=2" %%i in ('DATE /t') do set "DT=%%i" |
...
...
...
...
...
set DATETIME=%DT% %TM_HH%:%TM_MM% |
...
...
...
...
...
for /F "delims=" %%a in (taskProperty_template.xml) DO ( |
...
...
setlocal EnableDelayedExpansion |
...
>> taskProperty.xml echo(!line:%search%=%replace%! |
...
...
-----
Resulting taskProperty Resulting taskProperty file, with search_string "TIMEZERO" replaced (taskProperty.xml)
----
Code Block |
---|
|
<?xml version="1.0" encoding="UTF-8"?> |
...
<taskProperties xsi:schemaLocation="http://www.wldelft.nl/fews http://fews.wldelft.nl/schemas/version1.0/taskProperties.xsd" xmlns="http://www.wldelft.nl/fews" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> |
...
<description>ImportNOAAGFSdata_scheduled</description> |
...
...
<workflowId>Import_GFS_0.25_Schedule</workflowId> |
...
...
...
<time0>14-06-2021 11:20</time0> |
...
...
...
<forecastPriority>Normal</forecastPriority> |
...
<makeForcastCurrent>true</makeForcastCurrent> |
...
Solution Python
The user opted for a Python script to update the systemtime.
Now my solution has been to include a Python script prior to the FEWS call within my batch file.
Code Block |
---|
language | bash |
---|
linenumbers | true |
---|
collapse | true |
---|
|
cd C:\FEWS\
python .\WindowsTaskScheduling\refreshT0.py C:/FEWS/WindowsTaskScheduling/TaskRun_Update_Daily_Met_Gob.xml UpdateDailyMetGob
.\bin\windows\Delft-FEWS.exe "runTask=C:\FEWS\WindowsTaskScheduling\TaskRun_Update_Daily_Met_Gob.xml" |
This is the Python script:
Code Block |
---|
language | py |
---|
linenumbers | true |
---|
collapse | true |
---|
|
import sys
import datetime
import pytz
XML_PATH = sys.argv[1]
WORKFLOW_ID = sys.argv[2]
s = '''<?xml version="1.0" encoding="UTF- |
...
8"?>
<taskProperties xsi:schemaLocation="http://www.wldelft.nl/fews http://fews.wldelft.nl/schemas/version1.0/taskProperties.xsd" xmlns="http://www.wldelft.nl/fews" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<description>Update daily gobs (scheduled task)</description>
<userId>mm</userId>
<workflowId>{}</workflowId>
<taskSelection>
<singleTask>
<time0>{}</time0>
</singleTask>
</taskSelection>
<forecastPriority>Normal</forecastPriority>
<makeForcastCurrent>true</makeForcastCurrent>
</taskProperties>
'''
cur = datetime.datetime.now(tz=pytz.timezone("EST"))
with open(XML_PATH, "w") as f:
f.write(s.format(WORKFLOW_ID, cur.isoformat())) |