%SYSTEM.Task

17 views
Skip to first unread message

Bill Farrell

unread,
Jan 20, 2012, 11:50:13 AM1/20/12
to intersy...@googlegroups.com
Is it possible to leverage Task to schedule a new background task to run in MV?  The Management Portal intimates that you can write a new class that inherits %SYSTEM.Task, but I'm not coming up with an example in the doc.  (Maybe I'm searching wrong.)  I can't be the first to ask, so if someone has done this, a quick example would be helpful.  Given the property list in %SYSTEM.Task, it doesn't look impossible or tremendously difficult -- if you know what switches to flip and incantations to mumble (like how to run an MVBasic routine; the one I have in mind has a #pragma, thus a pointer in the VOC).

One of the things that always irritated me about Pick/UV/et al is when the system restarts, somebody (usually moi) has to remember to start phantoms by hand.  If the built-in task manager can be leveraged to start periodic or on-startup MV tasks that would be pretty darn neat.  Automagic = Good.

Also, if it's possible, how would a task consume a seat?  (Just out of curiosity...)

Bill

Ed Clark

unread,
Jan 20, 2012, 12:00:33 PM1/20/12
to intersy...@googlegroups.com
There are probably lots of ways to do this. As a quick example, copied from some test code:

PROG="SomeCatalogEntry"
task="%SYS.Task"->OpenId(PROG)
if task='' then
task="%SYS.Task"->%New()
task->Name=PROG
task->NameSpace=SYSTEM(1052)
task->OpenOutputFile=1
task->OutputFileIsBinary=1
task->OutputFilename=PATH
task->RunAsUser=@Authorization
task->Settings=$lb("ExecuteCode",'MV ':DQUOTE(PROG))
task->TaskClass="%SYS.Task.RunLegacyTask"
task->TimePeriod=5
task->TimePeriodEvery=1
task->Type=2
st=task->%Save()
if st#1 then abortm "failed to save task ":$SYSTEM.STATUS->GetErrorText(st)
end
id=task->%Id()
if id='' then abortm "task has no id ":$SYSTEM.STATUS->GetErrorText(st)
$kill task
st="%SYS.Task"->Resume(id)
if st#1 then abortm "resume failed ":$SYSTEM.STATUS->GetErrorText(st)
st="%SYS.Task"->RunNow(id)
if st#1 then abortm "runNow failed ":$SYSTEM.STATUS->GetErrorText(st)

SomeCatalogEntry is a basic program that has been cataloged. It gets run by the task using the MV command, though you could probably use DO ^rtnName as well.

> --
> You received this message because you are subscribed to the Google Groups "InterSystems: MV Community" group.
> To post to this group, send email to Cac...@googlegroups.com
> To unsubscribe from this group, send email to CacheMV-u...@googlegroups.com
> For more options, visit this group at http://groups.google.com/group/CacheMV?hl=en

Dawn Wolthuis

unread,
Jan 20, 2012, 12:12:13 PM1/20/12
to intersy...@googlegroups.com
Does this example help? I am not taking the time to figure out if it would. This was our first effort with tasks (I am not the author). I stripped out comments as most were history and were not going to help. What we are doing in this task is also not relevant, but you can see we send reminder email messages. In SMP we schedule this task for sometime at night. 
--dawn

Class SignUpNow.ReminderSender Extends %SYS.Task.Definition [ Language = mvbasic ]
{

Method OnTask() As %Status
{
    today = Date()
    sqlrs = "%ResultSet"->%New("SignUpNow.ReminderQuery:ReminderQuery")
    tSC = sqlrs->Execute(today)
    email = ""
    postingTitle = ""
    postingTime = ""
    signupId = ""
    postingId = ""
    firstName = ""
    lastName = ""
    fullName = ""
    loop while sqlrs->Next(nSC) do
        signupId = sqlrs->Get("signupId")
        postingId = sqlrs->Get("postingId")
        email = sqlrs->Get("email")
        postingTitle = sqlrs->Get("title")
        postingTime = sqlrs->Get("stime")
        firstName = sqlrs->Get("fname")
        lastName = sqlrs->Get("lname")
        fullName = firstName : " " : lastName
        url = @ME->GetPostingURL(postingId)
        reminderEmail = "SignUpNow.ReminderMessage"->%New(postingTitle, fullName, postingTime, url, postingId)
        body = reminderEmail->Message
        subject = reminderEmail->Subject
        "Util.Util"->SendMail(email, body, subject)
        r.signup = "S.SignUp"->%OpenId(signupId)
        if r.signup = "" then
            "Util.Util"->LogOpenIdError("'SignUpNow.ReminderSender'->OnTask S.SignUp", signupId)
        end else
            r.signup->Reminder = "Sent"
            r.signup->%Save()
        end
    repeat
    return 1
}

ClassMethod GetPostingURL(postingId) As %Status
{
    server = %request->GetCgiEnv("SERVER_NAME")
    url = "Util.URLMap"->GetURLPreParms("SignUpFor.StartPage.cls", server)
    url := "?PostingId="
    url := postingId
    return url
}

}


--
You received this message because you are subscribed to the Google Groups "InterSystems: MV Community" group.
To post to this group, send email to Cac...@googlegroups.com
To unsubscribe from this group, send email to CacheMV-u...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/CacheMV?hl=en



--
Dawn M. Wolthuis

Take and give some delight today

Bill Farrell

unread,
Jan 20, 2012, 12:13:12 PM1/20/12
to InterSy...@googlegroups.com
Awesome, thanks!  I figured that's what Task was there for.   When I create my version and compile it how does the Task Manager in the Portal become aware of it; that is, it shows up in the list of possible tasks to run?

I'll work on this much for now.  Thanks again.
B

Bill Farrell

unread,
Jan 20, 2012, 12:21:02 PM1/20/12
to intersy...@googlegroups.com
Beautiful, my friend, thanks!  I thought it would be pretty straightforward after seeing a quick example.  It's the creation of a task, using the definitions properly I needed a quick cookbook for.  Between the two examples, I can get what I want.

I'm likin' this.  A lot.

Thanks!
B

Bill Farrell

unread,
Jan 20, 2012, 2:48:19 PM1/20/12
to intersy...@googlegroups.com
Thanks for the examples.  The class Dawn provided plus the code Ed did made for the right amount of information. I had a bit of trouble explaining what I wanted to the Task Scheduler, but once I got that settled (only a few minutes) now I'm importing sensor data beautifully.

I haven't decided want I want to do with radar sequences yet;  StormPredator outputs a nice animated GIF of a relatively small size (a few K).  I'm looking at the doc for binary streams, mulling over the best way to attach images to sensor data.  The combination is useful for doing studies to determine which combination of solar or wind generation would be most practical.  The sensor data I've got will be useful for managing various sensors for irrigation, power management, etc.

In the thread history there is a good example of setting up a MVC for Zen.  Dawn, your vids are about to be extremely helpful (I subscribed to your channel a while back.  Now I have enough data to work with.)

Onward.


B



On Fri, 2012-01-20 at 11:12 -0600, Dawn Wolthuis wrote:

Tony Gravagno

unread,
Jan 24, 2012, 6:24:25 PM1/24/12
to InterSy...@googlegroups.com
Of course this is the Caché forum, but in the interest of accuracy...
 
In Pick (D3) phantoms are easily started with a single line in the user-coldstart item in dm,md.  D3 also has a background scheduler which is automatically started by system-coldstart to restart scheduled tasks (works same as cron).
 
For U2, you're right, the functionality isn't built-in.  But programs can be written pretty quickly to accomplish the task of auto-starting functionality.  So the statement "somebody (moi) has to remember to start phantoms by hand" isn't entirely accurate.  It's more "we have chosen to start phantoms by hand because we prefer not to have to automate that process ourselves."  Note, you've obviously made a different choice in Caché with %SYS.Task.
 
Respectfully,
T
 
 


From: Bill Farrell
Reply all
Reply to author
Forward
0 new messages