cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

We are happy to announce the new Windchill Customization board! Learn more.

Creating Custom Scheduled Jobs

MichaelSchumach
7-Bedrock

Creating Custom Scheduled Jobs

1.  I have a custom scheduled job created but it always runs in context 'site' and always returns null.  I understand this is by design.

2.  When I try to schedule my custom job in my org, my custom job name does not display in the job listbox to choose.  The custom job name only displays when I am in the job administrator scheduler for 'site'.

3.  I am struggling how to get my custom job name to display in the job administrator scheduler for my 'org' and have not been able to verify if my custom job java code is correct.   See the code below.

 

Any hints or suggestions are appreciated.

Thanks, Mike

 

 

package ext.customers.provisur.customJobs;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.util.Date;
import java.util.Iterator;
import java.util.Locale;
import java.util.logging.FileHandler;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;

import wt.doc.WTDocument;
import wt.epm.EPMDocument;
import wt.epm.EPMDocumentMaster;
import wt.epm.build.EPMBuildRule;
import wt.fc.ObjectIdentifier;
import wt.fc.ObjectReference;
import wt.fc.ObjectVector;
import wt.fc.ObjectVectorIfc;
import wt.fc.PagingQueryResult;
import wt.fc.Persistable;
import wt.fc.PersistenceHelper;
import wt.fc.QueryResult;
import wt.fc.collections.WTArrayList;
import wt.fc.collections.WTList;
import wt.inf.container.ContainerSpec;
import wt.inf.container.WTContained;
import wt.inf.container.WTContainerHelper;
import wt.inf.container.WTContainerRef;
import wt.log4j.LogR;
import wt.org.WTOrganization;
import wt.part.WTPart;
import wt.pds.StatementSpec;
import wt.pom.PersistenceException;
import wt.query.BasicPageableQuerySpec;
import wt.query.ClassAttribute;
import wt.query.PageableQuerySpec;
import wt.query.PagingSessionSpec;
import wt.query.QuerySpec;
import wt.query.SearchCondition;
import wt.query.SubSelectExpression;
import wt.representation.Representable;
import wt.representation.RepresentationHelper;
import wt.util.WTAttributeNameIfc;
import wt.util.WTContext;
import wt.util.WTException;
import wt.util.WTProperties;
import wt.vc.Iterated;
import wt.vc.IterationInfo;
import wt.vc.VersionControlHelper;
import wt.vc.Versioned;
import wt.viewmarkup.DerivedImage;

import com.ptc.wvs.common.util.VSResult;
import com.ptc.wvs.common.util.WVSProperties;
import com.ptc.wvs.server.schedule.ScheduleJobs;
import com.ptc.wvs.server.schedule.ScheduledJobQueries;
import com.ptc.wvs.server.ui.UIHelper;
import com.ptc.wvs.server.util.PublishUtils;

public class PTCustomJobs {
private static String schema;
public static String WTHOME = "D:/ptc/Windchill_11.x/Windchill" ;
public static String FILENAME = "scheduler_Prefix109_" ;
public static PrintWriter theLogFile = null ;
public static String theLogFileName = "";

// Using Logger rather than WVSLogger because WVSLogger is not a Supported API and this
// class double as an example.
private static final Logger logger = LogR.getLogger(PTCustomJobs.class.getName());
static {
boolean verbose = true;

String propValue = WVSProperties.getPropertyValue("publish.service.verbose");
if ((propValue != null) && propValue.equalsIgnoreCase("TRUE")) {
verbose = true;
}

if (verbose && logger.getLevel() == null) {
logger.setLevel(Level.DEBUG);
}

}


// public static WTList PTPrefix109() {
public static QuerySpec PTPrefix109() {

/*
* test to publish only 109-11**
*/
//schema = WTProperties.getLocalProperties().getProperty("wt.erp.schema");
//WTHOME = WTProperties.getLocalProperties().getProperty("wt.home") ;

logger.debug("starting prefix109");
WTList wtl = new WTArrayList();
QuerySpec qs = null;
QueryResult qr = null;
try {
qs = new QuerySpec(EPMDocumentMaster.class);
SearchCondition sc1 = new SearchCondition(EPMDocumentMaster.class,
EPMDocumentMaster.NUMBER,
SearchCondition.LIKE, "109-11%");
/*
SearchCondition sc2 =
new SearchCondition(EPMDocumentMaster.class,
EPMDocumentMaster.DISPLAY_TYPE,
SearchCondition.EQUAL, "Drawing"
);
*/
SearchCondition sc2 =
new SearchCondition(EPMDocumentMaster.class,
EPMDocumentMaster.DOC_TYPE,
SearchCondition.EQUAL, "CADDRAWING"
);

/*
SearchCondition sc3 =
new SearchCondition(WTOrganization.class,
WTOrganization.NAME,
SearchCondition.EQUAL, "Provisur"
);
*/

WTContainerRef cr = ScheduleJobs.getCurrentContainer();
if (cr != null) {
logger.debug("filter CAD drawings by container-" + cr.getName() );
ContainerSpec cs = new ContainerSpec();
cs.addSearchContainer(cr);
qs.setAdvancedQueryEnabled(true);

qs.appendWhere(sc1, new int[] {0});
qs.appendAnd();
qs.appendWhere(sc2, new int[] {0});
//qr = PersistenceHelper.manager.find((StatementSpec) qs);
/*
while (qr.hasMoreElements()) {
//doc = (Representable)((Object[])qr.nextElement())[0];
//wtl.add(doc);
wtl.add(qr.nextElement());
}
*/

}
} catch (Exception e) {
logger.error("proviScheduleJobPrefix109(): ", e);
qr = new QueryResult();
}

//return new WTArrayList(qr);
return qs;
}

}

 

1 ACCEPTED SOLUTION

Accepted Solutions
Florent
14-Alexandrite
(To:MichaelSchumach)

I think there is a mistake in your properties:

Clipboard.png

 
 

You should have an identical name either publishPTPrefix109 or PTPrefix109.

 

 

Florent ROUSSEL
www.4cad.ca

View solution in original post

4 REPLIES 4

Maybe a better way for me to approach my issue with the community is forget about the Java code first and focus on why I cannot run my custom schedule job in my 'org' context?

 

I added my entries to wvs.properties.xconf

   <Property default="publishPTPrefix109" name="schedulejobs22"/>
   <Property default="publishPTPrefix109" name="publishPTPrefix109.description"/>
   <Property default="ext.custoers.provisur.customJobs" name="PTCustomJobs.class"/>
   <Property default="PTPrefix109" name="PTPrefix109.method"/>
   <Property default="true" name="PTPrefix109.enableOnContainers"/>
   <Property default="publishJob" name="PTPrefix109.jobType"/>

 

I then ran xconfmanager -p

 

when I go to browse / site / wvs job scheduler administration, I see my job listed and if I run it, it will run in context 'site'

 

When I go to browse / org / wvs job scheduler administration, I do not see my job listed.   

 

The question is Why?

 

thanks

Mike

 

 

Florent
14-Alexandrite
(To:MichaelSchumach)

I think there is a mistake in your properties:

Clipboard.png

 
 

You should have an identical name either publishPTPrefix109 or PTPrefix109.

 

 

Florent ROUSSEL
www.4cad.ca

 

In wvs.properties.xconf file (i don't believe all the names must be the same. 😞

    <!--  my job name that displays in the wvs job scheduler administration  ->

   <Property default="PTCustomJobs" name="schedulejobs22"/>
   <Property default="PTPrefix109" name="PTCustomJobs.description"/>

   <!--  my PTCustomJobs.class file resides in this codebase subfolder  ->
   <Property default="ext.customer.provisur.customJobs" name="PTCustomJobs.class"/>

   <!--   my Method in my class has a name PTPrefix109  ->
   <Property default="PTPrefix109" name="PTCustomJobs.method"/>
   <Property default="true" name="PTCustomJobs.enableOnContainers"/>
   <Property default="publishJob" name="PTCustomJobs.jobType"/>

 

After xconfmanager -p and restarting windchill services, I tried running my custom job in the scheduler and now I receive the java error ClassNotFoundException.   See below

 

2020-02-27 07:53:26,078 ERROR [WVSScheduleQueue.SchedulingThread] com.ptc.wvs.server.schedule.Schedulable Administrator - executeQuery(): mQueryClass=ext.customer.provisur.customJobs mQueryMethod=PTPrefix109
java.lang.ClassNotFoundException: ext.customer.provisur.customJobs

 

 

Is the error telling me the windchill classpath is incorrect?  mQueryClass appears to show the correct location under codebase as "ext.customer.provisur.customJobs" where the class file resides.   The mQueryMethod has the correct name PTPrefix109.

 

Thanks.

I have resolved my situation with setting up the wvs.properties.xconf file correctly.  Thanks to the reply by froussel_ca and several other links.

 

Other links helpful include: https://support.ptc.com/help/wnc/r11.2.0.0/en/index.html#page/Windchill_Help_Center/WCCG_BusLogicCust_WCVisualization_CustPublish.html

 

https://www.ptc.com/en/support/article/CS211115

 

My corrected wvs.properties.xconf entries are below:

 

   <Property default="PTCustomJobs" name="schedulejobs22"/>

   <Property default="PTPrefix109" name="PTCustomJobs.description"/>
   <Property default="ext.customers.provisur.customJobs.PTCustomJobs" name="PTCustomJobs.class"/>
   <Property default="PTPrefix109" name="PTCustomJobs.method"/>
   <Property default="true" name="PTCustomJobs.enableOnContainers"/>
   <Property default="publishJob" name="PTCustomJobs.jobType"/>
 
Schedulejobs22 name PTCustomJobs needed to be in each of the entries below as shown above.  The PTCustomJobs.class entry does require the full path of the class.   This is stated in the documentation just remember to put the actual class name in the entry not just the path name.
 
The backgroundMethodServer log file provided the other error messages needed to fix the java routine.
 
Thanks to everyone.
 
Mike
Top Tags