How to add dynamic context variable to TAC job

Not applicable

How to add dynamic context variable to TAC job

Hello folks,
I have a job that I want to launch on daily basis.
In general it should take yesterday's date format it into YYYYMM and use it in folder path.
HOWEVER, we want to have an option to overwrite this option in case of emergency, but we don't want to open Talend Studio, open project and run the job (as we dont plan to have Studio on prod env).
Natural choice is to configure context variable and use it to replace default values.

It was working for manual executions, but right now we to schedule it for automated execution, and sadly, I dont know how to pass dynamic parameter, because my first hit does not work:

: midt.mk_scheduling_test_0_2.MK_scheduling_test - TalendJob: 'MK_scheduling_test' - Start.
ala ma kota
TalendDate.formatDate("yyyyMM",TalendDate.getCurrentDate())
201605
: midt.mk_scheduling_test_0_2.MK_scheduling_test - TalendJob: 'MK_scheduling_test' - Done.
could you help me?
Six Stars JR
Six Stars

Re: How to add dynamic context variable to TAC job

You cannot use Java methods as values for contexts, just literal values. You should incorporate the method call TalendDate.formatDate("yyyyMM",TalendDate.getCurrentDate()) into the job and only use the returned value if your context variable "date" is not empty. 
Like this: 
(context.date == null || "".equals(context.date)) ? TalendDate.formatDate("yyyyMM",TalendDate.getCurrentDate()) : context.date
Not applicable

Re: How to add dynamic context variable to TAC job

Yeah.. that was my backup plan, but this means I have to edit already developed job. I was thinking about some external injection.
Thank you!
Six Stars

Re: How to add dynamic context variable to TAC job

Hi,
You can also use a properties file or db table, you have just to edit your date in the file or in the table.
Best regards,
Amine
 
Six Stars JR
Six Stars

Re: How to add dynamic context variable to TAC job

Sorry to say but using an external properties file will not really solve the problem at hand as you can only provide literal values in there as well. Furthermore, this - as well as using a db table - will also require manipulating the already developed job. What is been looking for is some sort of "value to code" which to my knowledge is not possible or let's say very challenging.
Sixteen Stars

Re: How to add dynamic context variable to TAC job

JoRoesecke is right. I believe he has suggested the best way of achieving this. It is the way that I would use. A simple modification to the job will save you from spending ages trying to put together a "gaffer tape" solution using properties files. However, if you really want to leave the job alone (maybe you have lost the source code for it, I don't know), maybe you can make use of the of Metaservlet functionality of the TAC. I use this to call Talend DI jobs from the ESB runtime. It seems pointless to me to waste ESB Runtime CPU cycles carrying out DI jobs, but I need to trigger them from Camel Routes. So to do this I initiate DI jobs from the Runtime using the metaservlet. Take a look here for instructions on how to do this (https://help.talend.com/search/all?query=Calling+metaServlet&content-lang=en) and here for API instructions (https://help.talend.com/pages/viewpage.action?pageId=261845686).