Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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
languagetext
collapsetrue
<?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>

...


    <userId>fews</userId>

...


    <workflowId>Import_GFS_0.25_Schedule</workflowId>

...


    <taskSelection>

...


        <singleTask>

...


            <time0>TIMEZERO</time0>

...


        </singleTask>

...


    </taskSelection>

...


    <forecastPriority>Normal</forecastPriority>

...


    <makeForcastCurrent>true</makeForcastCurrent>

...


</taskProperties>

...

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
languagebash
linenumberstrue
collapsetrue
@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 TM_HH=%TIME:~0,2%

...


set TM_MM=%TIME:~3,2%

...


set TM_HH=%TM_HH: =0%

...


set TM_MM=%TM_MM: =0%

...



set DATETIME=%DT% %TM_HH%:%TM_MM%

...


echo %DATETIME%

...



set "search=TIMEZERO"

...


set "replace=%DATETIME%"

...


del taskProperty.xml

...


for /F "delims=" %%a in (taskProperty_template.xml) DO (

...


   set line=%%a

...


   setlocal EnableDelayedExpansion

...


   >> taskProperty.xml echo(!line:%search%=%replace%!

...


   endlocal

...


)

-----
Resulting taskProperty Resulting taskProperty file, with search_string  "TIMEZERO"  replaced (taskProperty.xml)
----


Code Block
collapsetrue
<?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>

...


    <userId>fews</userId>

...


    <workflowId>Import_GFS_0.25_Schedule</workflowId>

...


    <taskSelection>

...


        <singleTask>

...


            <time0>14-06-2021 11:20</time0>

...


        </singleTask>

...


    </taskSelection>

...


    <forecastPriority>Normal</forecastPriority>

...


    <makeForcastCurrent>true</makeForcastCurrent>

...


</taskProperties>


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
languagebash
linenumberstrue
collapsetrue
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
languagepy
linenumberstrue
collapsetrue
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()))