Written by

Question Gary Koester · Nov 11, 2021

#5003 not implemented

I am trying to create a scheduled task but get not implemented error when I try to run it.

Class PICIS.Core.Tasks.CleanEntry Extends %RegisteredObject
{

ClassMethod ClearTasks(pBackupFile As %String = "d:\Temp\BackupTasks.xml", pDelete As %Boolean = 0)
{
    // Create backup file
    Set tBackup = ##class(%Stream.FileCharacter).%New()
    Set tBackup.Filename = pBackupFile
    Do tBackup.WriteLine("<?xml version=""1.0"" encoding=""UTF-8""?>")
    Do tBackup.WriteLine("<Tasks>")

    // Delete loop
    Set tCount = 0
    Set tSC = $$$OK
    Set tRS = ##class(%SQL.Statement).%ExecDirect(, "Select ID From %SYS.Task Where Namespace = ? And TaskClass = ?", PICIS, "picis.core.tasks.senddelayedtrigger")
    While tRS.%Next() {
        Set tTask = ##class(%SYS.Task).%OpenId(tRS.ID)
        Set tSC = tTask.XMLExportToString(.tExport)
        If $$$ISERR(tSC) {
            Write !,"Problem trying to export TASK ID ",tRS.ID
            Do $System.Status.DisplayError(tSC)
            Quit
        }
        Do tBackup.WriteLine($ZConvert(tExport, "O", "UTF8"))

        // Delete?

        If pDelete {
            Set tSC = ##class(%SYS.Task).%DeleteId(tRS.ID)
            If $$$ISERR(tSC) {
                Write !,"Problem trying to delete TASK ID ",tRS.ID
                Do $System.Status.DisplayError(tSC)
                Quit
            }
        }
        Set tCount = tCount + 1
    }
    // Close backup file
    Do tBackup.WriteLine("</Tasks>")
    Set tSC = tBackup.%Save()
    If $$$ISERR(tSC) {
        Write !,"Problem saving backup file"
        Do $System.Status.DisplayError(tSC)
        Quit
    }
    Write !!,"Backed up ",$Select(pDelete:"and Deleted ", 1:""),tCount," Tasks"
}
}

Product version: Caché 2017.1

Comments

Vic Sun · Nov 11, 2021

Can you see where the not implemented is being thrown?

0
Gary Koester · Nov 11, 2021

No, its a new one for me. It is a mystery to me.

0
Vic Sun  Nov 11, 2021 to Gary Koester

If you debug the class and go through it can you try to identify which line is throwing the error?

0
Robert Cemper · Nov 11, 2021

I assume your Classmethod runs from console / terminal.
running as scheduled Task you are always running in Background.
So where do you expect all the WRITE to go.
I did neither see a log file or a Spool device.  

0
Gary Koester  Nov 12, 2021 to Robert Cemper

The code was given to me from Intersystems. I can remove the writes.

0
David Hockenbroch · Nov 11, 2021

There's a syntax error in this line:

Set tRS = ##class(%SQL.Statement).%ExecDirect(, "Select ID From %SYS.Task Where Namespace = ? And TaskClass = ?", PICIS, "picis.core.tasks.senddelayedtrigger")

PICIS needs to be in quotes.

That wouldn't typically cause a not implemented error, though. Are you getting any errors when you try to compile the class?

0
Gary Koester  Nov 12, 2021 to David Hockenbroch

No it compiles successfully

0
David Hockenbroch · Nov 11, 2021

To use something in the task scheduler, you have to create a class that extends %SYS.Task.Definition. Within that class you have to define:

Method OnTask() As %Status{
    //The stuff you want to happen when the task is scheduled goes here.
    //In your case, that probably means calling your task method.
}

If that method is not defined, you get the "Not Implemented" error. If you've created such a class, make sure the method had the right name, isn't a classmethod, is As %Status, and does return a %Status. Also make sure the class is compiling correctly.

0
Gary Koester  Nov 12, 2021 to David Hockenbroch

I added the Method and now have a different error.

<UNDEFINED>zOnTask+3^PICIS.Core.Tasks.CleanEntry.1 *pBackupFile
0
Gary Koester  Nov 12, 2021 to Gary Koester

I have not written much of this code so I am a beginner and learning.

0
David Hockenbroch  Nov 12, 2021 to Gary Koester

That's okay! That's what we're here for. What exactly is in your OnTask method?

0
Gary Koester  Nov 18, 2021 to David Hockenbroch

Finally getting back to this. Where does the method live. In the file directory?

0
David Hockenbroch  Nov 18, 2021 to Gary Koester

Gary, if you want to put something into the Cache Task Manager, you have to create a class that extends %SYS.Task.Definition and put the OnTask method there.

I wrote a how-to on using the task manager after you posted this. It might help you.

0
Gary Koester  Nov 18, 2021 to David Hockenbroch

Thanks. Ill take a look

0