Python Toolbox Tool and Creating a Geoprocessing Service

2974
13
Jump to solution
10-02-2012 07:12 AM
ChanningDale
New Contributor III
Hello all,

I've created a custom tool in a Python toolbox and want to publish it as a geoprocessing service.  It has three parameters, and it uses Make Feature Layer tool, Select By Location Tool, and the Execute Reviewer Batch Job tool.  It runs perfectly in Desktop.

Yet, when I publish it and go to run it as a service, ArcGIS Server says that it runs successfully, but I get no results back.  I honestly don't think that any of my code runs, even though ArcGIS Server says that it completed.  I even started picking apart my tool to see if there was an issue with certain parts, but even when I tear it down to something extremely simple, I get nothing from ArcGIS Server.  I've registered the databases and folder locations that I'm using too with Server.

Has anyone else been having issues trying to publish their geoprocessing tools to services?  Could I get some help?
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
ChanningDale
New Contributor III
I thought I'd give a short update on this issue.  The reason why I wasn't getting any results back in my SDE database was because I had some hard-coded paths to databases and features classes in my script, and when I published my toolbox to ArcGIS Server, those objects were getting copied locally on the server, which I was unaware of.  I didn't want this to happen because I needed the results to be written to an SDE database so that I could query to see if results were actually returned by the tool.  All I had to do was remove those hard-coded paths, make them parameters and set them as constants, and make sure that I had all my data sources registered on the server's data store.  The tool has been running the way it was designed.

Also, my code was getting changed in my toolbox when I published it to the server, so I had to go to the copy on the server and change some of the code back to the way it was before publication.

View solution in original post

0 Kudos
13 Replies
KevinHibma
Esri Regular Contributor
I havent personally used the Batch Reviewer tool as a GP Service, but the first two tools shouldnt have any issues.
As a quick test to be sure that isn't the issue, can you change the output to just a feature layer from the Select tool and publish this? Do you get back the selected features from the service?
Depending on this test result it'll give you an idea if its a Py-Toolbox/data issue, or specific to the Reviewer tool.
0 Kudos
ChanningDale
New Contributor III
I had already set up the service to create two layers, one from the Make Feature Layer and another from the Selection (which I'm also making in to a feature layer).  I'm trying to output them to a folder that the service can see, but I get nothing.  Should I be outputting this to a map instead?
0 Kudos
KevinHibma
Esri Regular Contributor
Right - folder isn't a supported return type. Its probably been mapped to "string", so your service isn't returning anything.
Or do I have it wrong - are you actual output types FEATURE (class/layer/etc)?

Can you post your code from
def getParameterInfo(self):
0 Kudos
ChanningDale
New Contributor III
Here are my parameters.  The first one is accepting an input feature class, the second is a query where the user is passing in a list of OBJECTIDs from the input feature class, and the last variable is a value that helps a function later on in the code query a table for a path name to a Data Reviewer check.

    def getParameterInfo(self):
        ### Define parameter definitions

        param0 = arcpy.Parameter(
            displayName="Input Feature Class Location",
            name="edit_fc",
            datatype="Feature Class",
            parameterType="Optional",
            direction="Input",
            multiValue=True)

        param0.filter.list = ["Polygon", "Polyline", "Point"]

        param1 = arcpy.Parameter(
            displayName="OID Query Expression",
            name="oid_query",
            datatype="SQL Expression",
            parameterType="Optional",
            direction="Input")

        param1.parameterDependencies = [param0.name]

        param2 = arcpy.Parameter(
            displayName="Workflow",
            name="wf_name",
            datatype="String",
            parameterType="Optional",
            direction="Input")
        
        params = [param0, param1, param2]
        return params


Ultimately, with this tool (including the Data Reviewer part of it), I'm writing records to the Reviewer table after the Execute Reviewer Batch Job tool runs and querying the database to find out if those records are there.  The only thing I want to return is if those records exist or not; a pass or fail.
0 Kudos
KevinHibma
Esri Regular Contributor
Ok that clears it up, thanks.

Right now your tool has no outputs, so you could return pass/fail by simply having the tool "fail" with an AddError. That probably isn't the best approach.
If you want an actual return type, you can add a new output parameter of Boolean and set it as True or False to say its passed or failed.
Or do you want just a simple string (AddMessage) to say whether or not the records exist (based on your logic).
With any of the Message approaches you'll have to make sure you turn Messages on the Service to the appropriate setting (Info|Warning|Error).

Ultimately it comes down to your workflow - how do you want to tell the service user about the records? Using a message, using a return parameter or having the service simply succeed or fail.
0 Kudos
ChanningDale
New Contributor III
So, even though it works correctly from the Desktop the way that it is now, it won't work correctly as a geoprocessing service if I don't have outputs?  I mean, when I run my tool, no errors get written to the Data Reviewer database even when I pass in features that I KNOW are going to return errors.  As far as I can see, NOTHING happens when I run the geoprocessing service.

I should mention that this geoprocessing service is going to be used in a Flex application, not in a geoprocessing widget, but called in underlying code.
0 Kudos
KevinHibma
Esri Regular Contributor
I guess I dont completely understand how it works on Desktop and what the return types are there.
From the code snippet I assumed it didnt return anything in Desktop as there wasnt any outputs.

I just read the help on this tool... it sounds like the tool, by default provides "results" in a couple ways:
The Reviewer batch job results are written to the specified session (indicated by Session) in the Reviewer Workspace.
A summary of the batch job is displayed in the Results window.
The output parameter for this tool is a table view of one row of the REVBATCHRUNTABLE table in the Reviewer Workspace. The row represents the record created when the batch job is executed.


Perhaps when this tool is run in your script on desktop, the output table is simply returned. With a GP Service you have to setup the output parameter specifically for this table to be returned.

Looking at its Python usage:
# execute the batch job
res = arcpy.ExecuteReviewerBatchJob_Reviewer(rev_workspace,session,batch_job_file,prod_workspace)
# get the output table view from the result object
tbl = res.getOutput(0)


You'll have to set that "tbl" as your output table and pass that back. Again, assuming its that table you want.
0 Kudos
KevinGooss
Occasional Contributor
I think you should just add another parameter that has a direction of Output and call it something like result and make it a string.
When you test to see if the table has had records added write a statement that compares the number of records added with what you expect and if it is equal return "true" in your output param otherwise "false".
If you don't have any params with type output you are not going to get any output.
0 Kudos
ChanningDale
New Contributor III
The only result I want from the tool is whether or not the features passed or failed.  The way that I programmed my tool to determine this is by querying the table that contains the results from the Execute Reviewer Batch Job tool by using the OBJECTIDs of the features that were checked since they are stored in that table.  If records are returned from the query, then one or more of the features failed.  If nothing is returned, then the features passed.

The Execute Reviewer Batch Job tool should, after executing, automatically write any error records to the REVTABLEMAIN table in the database containing the Data Reviewer schema.  This isn't happening in the service.  I don't think any of the individual tools are running.

When I run the tool from ArcMap before publishing it to a geoprocessing service, do the results have to be referencing the data in the map document or can I navigate to my inputs on the file system?
0 Kudos