|
VisualCron
»
Support
»
API
»
How to run a task using API
 Rank: Newbie
Joined: 2/16/2010(UTC) Posts: 5 Location: Sydney
|
I have attempted to use your API (4.9.40) to execute a remote task. I can succesfully run a Job but when it comes to running tasks it doesnt appear work. The jobid and taskid used are are correct. Any ideas? Server s = new Server(); Client c = new Client(); Connection conn = new Connection(); conn.Address = "testserver"; conn.UserName = "admin"; conn.PassWord = ""; conn.Port = 16444; conn.ConnectionType = Connection.ConnectionT.Remote; try { s = c.Connect(conn, true); } catch (VisualCronAPI.Client.ClientLoginFailedException ex) { Console.WriteLine(ex.Message); } s.Jobs.Tasks.Run("eecd5322-5831-4ad3-bd8e-23e21cf7ee6e", "9702725a-001c-43ab-a45c-1de45353b279"; Edited by user Friday, May 13, 2011 9:18:57 AM(UTC)
| Reason: Not specified
|
|
|
|
|
|
 Rank: Advanced Member
Joined: 2/26/2008(UTC) Posts: 1,107  Location: Amsterdam, The Netherlands Thanks: 39 times Was thanked: 66 time(s) in 57 post(s)
|
andyfordyce wrote:s.Jobs.Tasks.Run("eecd5322-5831-4ad3-bd8e-23e21cf7ee6e", "9702725a-001c-43ab-a45c-1de45353b279";
I think you miss the ')' behind this line. s.Jobs.Tasks.Run("eecd5322-5831-4ad3-bd8e-23e21cf7ee6e", "9702725a-001c-43ab-a45c-1de45353b279" ); Regards, Erik | Uses Visualcron since 2006. |
|
|
|
|
|
 Rank: Newbie
Joined: 2/16/2010(UTC) Posts: 5 Location: Sydney
|
Damn, I must have accidently deleted it when pasting the code into the post. This doesn’t appear to be my issue, any other ideas?
Thanks
|
|
|
|
|
|
 Rank: Advanced Member
Joined: 2/26/2008(UTC) Posts: 1,107  Location: Amsterdam, The Netherlands Thanks: 39 times Was thanked: 66 time(s) in 57 post(s)
|
Hi andyfordyce,
I moved this topic to the API section.
I looked at your issue and it looks like you are missing a third parameter which should the boolean: bolCheckConditions.
Here are the parameters when you're using the guids for the job and task:
string jobId, string taskId, bool bolCheckConditions
Regards, Erik | Uses Visualcron since 2006. |
|
|
|
|
|
 Rank: Newbie
Joined: 2/16/2010(UTC) Posts: 5 Location: Sydney
|
Hi
I have taken a further look at this and the run method is only accepting 2 arguments and not 3. Are you possibly using a different version of the API? I have also downloaded the API documentation from the VC website and there is no mention of the run method accepting 3 arguments.
Run(TaskClass) Run(JobClass, TaskClass) Run(String, String)
Any help on this is much appreciated.
Thanks
|
|
|
|
|
|
 Rank: Advanced Member
Joined: 2/26/2008(UTC) Posts: 1,107  Location: Amsterdam, The Netherlands Thanks: 39 times Was thanked: 66 time(s) in 57 post(s)
|
Hi,
I'm using the latest version 5.7.4 of VC. I'm not sure of the API version in here.
I see you can use the jobclass and the taskclass. Can you make two objects for the bob and the task and provide them in the run method?
If both objects are good (job and task) the run method should work. Did you tried this?
Regards Erik | Uses Visualcron since 2006. |
|
|
|
|
|
 Rank: Newbie
Joined: 5/15/2011(UTC) Posts: 2 Location: Sydney, Australia
|
I haven't tried to run jobs/tasks by their ID If you iterate the Jobs and Tasks to find your specific Job and/or Task, then pass the Job object or Task object into the appropriate run method it works for Jobs but not for tasks (same problem as Andy - version 4.9.40) There must be a bug in the API but there must be a work around as the VC client is able run a task directly Edited by user Sunday, May 15, 2011 4:15:53 AM(UTC)
| Reason: Not specified
|
|
|
|
|
|
 Rank: Advanced Member
Joined: 2/26/2008(UTC) Posts: 1,107  Location: Amsterdam, The Netherlands Thanks: 39 times Was thanked: 66 time(s) in 57 post(s)
|
Hi, I tried it this morning with VC version 5.7.4. I did manage to get a task running with the two string id's, but I wasn't able to reproduce it. Looks like the code I wrote worked only once... I also made two objects, one for the job, one for the task. I used the Get method with the id for this to get both objects. By using these two in the run method it did not work also. So I have the same conclusion as MArtin.Lanza: there must be a bug here. Regards, Erik | Uses Visualcron since 2006. |
|
|
|
|
|
 Rank: Administration
Joined: 2/23/2008(UTC) Posts: 6,169  Location: Sweden Thanks: 200 times Was thanked: 120 time(s) in 115 post(s)
|
Newer versions require 3rd parameter to tell if it should run the Task with Conditions or not. I can't tell right now if there is a specific problem in 4.9.40 but I do know that a lot have happened in the API since then. We used the sample from the TestClient in the API folder and added this method: Quote: private void btnRunTask_Click(object sender, EventArgs e) { if (s != null) { if (s.Connected) { // loop through all existing Jobs foreach (JobClass j in s.Jobs.GetAll()) { // find one Job with at least one Task if (j.Tasks.Count > 0) { AddToLog("Trying to run Task: " + j.Tasks[0].Name + " (" +j.Tasks[0].Id + ")"); // run Task and exit loop s.Jobs.Tasks.Run(j.Id, j.Tasks[0].Id, false); break; } } } } } This works every time for us. An interesting detail is that the overload method that takes two Id (Job and Task id) is used by the other "Run" methods. So, if that does not work and the other two works then you are sending the wrong Id's. Please try the above method to confirm. | |
|
|
|
|
|
 Rank: Advanced Member
Joined: 2/26/2008(UTC) Posts: 1,107  Location: Amsterdam, The Netherlands Thanks: 39 times Was thanked: 66 time(s) in 57 post(s)
|
Hi support, I used the third parameter and I'm not able to run the task... Code:JobClass jo = new JobClass(); jo = s.Jobs.Get("33f100d2-0e6d-4524-b64e-49d17d3e8287"); TaskClass ta = new TaskClass(); ta = s.Jobs.Tasks.Get("5c28384e-edaf-4156-818c-77c4764d02d5"); s.Jobs.Tasks.Run(jo, ta, false); If I use these commands I can change the activate flag: Code:s.Jobs.DeActivate(jo); s.Jobs.Tasks.DeActivate(ta); So I know the ID's are ok. Still I'm not able to run the task. The code is ok, there are no errors. Regards Erik Edited by user Monday, May 16, 2011 12:41:22 PM(UTC)
| Reason: Not specified | Uses Visualcron since 2006. |
|
|
|
|
|
 Rank: Administration
Joined: 2/23/2008(UTC) Posts: 6,169  Location: Sweden Thanks: 200 times Was thanked: 120 time(s) in 115 post(s)
|
The log file should probably show something about this. Could you check log_serverDATE.txt. If that does not contain _anything_ about this then we would like to see the log file from the api. You can find the location of that by opening the client->Manage client settings->Folders->Log. Close the client when you do the testing. | |
|
|
|
|
|
 Rank: Advanced Member
Joined: 2/26/2008(UTC) Posts: 1,107  Location: Amsterdam, The Netherlands Thanks: 39 times Was thanked: 66 time(s) in 57 post(s)
|
Hi, I looked at my logfiles, and the log_server20110516.txt is showing: Code:5/16/2011 12:49:05 PM Debug TcpClient accepted. 5/16/2011 12:49:05 PM Debug Before sending ClientConnection. 5/16/2011 12:49:05 PM Debug Before returning sslStream 5/16/2011 12:49:05 PM Debug New client connected. 5/16/2011 12:49:05 PM Debug Client: 5942572d-2879-4356-bc58-ba2eabdabd97 (10.5.107.16) has disconnected 5/16/2011 12:49:05 PM Debug AuthenticateAsServer, certificate name: CN=vc 5/16/2011 12:49:05 PM Debug Removed handlers for connection. 5/16/2011 12:49:05 PM Debug AuthenticateAsServer doneCN=vc 5/16/2011 12:49:05 PM Debug Entering RemoveConnection. 5/16/2011 12:49:05 PM Debug Waiting for client connection 5/16/2011 12:49:05 PM Debug ConnClass picked up. 5/16/2011 12:49:05 PM Debug ConnClass deactivated. 5/16/2011 12:49:05 PM Debug Connection removed from dictionary. 5/16/2011 12:49:05 PM Debug Before sending ClientConnection. 5/16/2011 12:49:05 PM Debug Connection: 5942572d-2879-4356-bc58-ba2eabdabd97 was removed 5/16/2011 12:49:06 PM Debug Using normal logon (False) 5/16/2011 12:49:06 PM Info User "VisualCron Default Admin" (admin) - Logged in succesfully through Socket (05465016-fb2f-4e61-a731-71ff564aafe6) 5/16/2011 12:49:06 PM Debug Updating login status for: 05465016-fb2f-4e61-a731-71ff564aafe6 5/16/2011 12:49:06 PM Debug Before sending ClientConnection. 5/16/2011 12:49:07 PM Comm IN: SERVERSETTINGSREQ 5/16/2011 12:49:07 PM Comm IN: LICENSEREQ The log_api20110516.txt doesn't contain any logs for this action and is not touched by my process. So I can't see anything about my Run method. --- If I do it again and also have the DeAvtivate statement in there I have this log: Code:5/16/2011 12:53:18 PM Debug TcpClient accepted. 5/16/2011 12:53:18 PM Debug Before sending ClientConnection. 5/16/2011 12:53:18 PM Debug Before returning sslStream 5/16/2011 12:53:18 PM Debug New client connected. 5/16/2011 12:53:18 PM Debug AuthenticateAsServer, certificate name: CN=vc 5/16/2011 12:53:18 PM Debug AuthenticateAsServer doneCN=vc 5/16/2011 12:53:18 PM Debug Waiting for client connection 5/16/2011 12:53:20 PM Debug Using normal logon (False) 5/16/2011 12:53:20 PM Info User "VisualCron Default Admin" (admin) - Logged in succesfully through Socket (28d57137-2330-4879-aa03-c1a97293b735) 5/16/2011 12:53:20 PM Debug Updating login status for: 28d57137-2330-4879-aa03-c1a97293b735 5/16/2011 12:53:20 PM Debug Before sending ClientConnection. 5/16/2011 12:53:20 PM Comm IN: SERVERSETTINGSREQ 5/16/2011 12:53:20 PM Comm IN: LICENSEREQ 5/16/2011 12:53:22 PM Debug Job (74) was added to processlist: _erik test 5/16/2011 12:53:22 PM Debug Task (82) was added to processlist: download file 5/16/2011 12:53:22 PM Info User "VisualCron Default Admin" - Set task state to: False 5/16/2011 12:53:22 PM Info Task started: download file (82) 5/16/2011 12:53:22 PM Debug Executing HTTP with parameters: 5/16/2011 12:53:28 PM Info Task completed: download file (82) 5/16/2011 12:53:28 PM Debug Setting previous task in TaskProcessCompleted: download file (5c28384e-edaf-4156-818c-77c4764d02d5) in job: _erik test 5/16/2011 12:53:28 PM Debug Process status - About to SendTaskProcess (82) 5/16/2011 12:53:28 PM Debug Process status - About to RemoveTaskProcess (82) 5/16/2011 12:53:28 PM Debug Client: 28d57137-2330-4879-aa03-c1a97293b735 (10.5.107.16) has disconnected 5/16/2011 12:53:28 PM Debug Task (82) was removed from processlist: download file 5/16/2011 12:53:28 PM Debug Removed handlers for connection. 5/16/2011 12:53:28 PM Debug Entering RemoveConnection. 5/16/2011 12:53:28 PM Debug ConnClass picked up. 5/16/2011 12:53:28 PM Debug ConnClass deactivated. 5/16/2011 12:53:28 PM Debug Connection removed from dictionary. 5/16/2011 12:53:28 PM Debug Before sending ClientConnection. 5/16/2011 12:53:28 PM Debug Connection: 28d57137-2330-4879-aa03-c1a97293b735 was removed 5/16/2011 12:53:28 PM Debug Job (74) was removed from processlist: _erik test 5/16/2011 12:53:28 PM Debug Next execution (2) for job '_erik test' is: 12:00:00 AM 5/16/2011 12:53:28 PM Info Job completed: _erik test 5/16/2011 12:53:28 PM Debug Saving Jobs Now it did work... --- Again and now use the Activate statement after the task run: Code:5/16/2011 12:56:27 PM Debug TcpClient accepted. 5/16/2011 12:56:27 PM Debug Before sending ClientConnection. 5/16/2011 12:56:27 PM Debug Entering RemoveConnection. 5/16/2011 12:56:27 PM Debug ConnClass picked up. 5/16/2011 12:56:27 PM Debug ConnClass deactivated. 5/16/2011 12:56:27 PM Debug Connection removed from dictionary. 5/16/2011 12:56:27 PM Debug Before sending ClientConnection. 5/16/2011 12:56:27 PM Debug Connection: e8d9186c-9358-48a2-ba4a-2438745ad9de was removed 5/16/2011 12:56:27 PM Debug Before returning sslStream 5/16/2011 12:56:27 PM Debug New client connected. 5/16/2011 12:56:27 PM Debug AuthenticateAsServer, certificate name: CN=vc 5/16/2011 12:56:27 PM Debug AuthenticateAsServer doneCN=vc 5/16/2011 12:56:27 PM Debug Waiting for client connection 5/16/2011 12:56:29 PM Debug Using normal logon (False) 5/16/2011 12:56:29 PM Info User "VisualCron Default Admin" (admin) - Logged in succesfully through Socket (005257fb-ecb0-416f-8177-b3a9c188463c) 5/16/2011 12:56:29 PM Debug Updating login status for: 005257fb-ecb0-416f-8177-b3a9c188463c 5/16/2011 12:56:29 PM Debug Before sending ClientConnection. 5/16/2011 12:56:29 PM Comm IN: SERVERSETTINGSREQ 5/16/2011 12:56:30 PM Comm IN: LICENSEREQ 5/16/2011 12:56:32 PM Debug Job (75) was added to processlist: _erik test 5/16/2011 12:56:32 PM Debug Task (83) was added to processlist: download file 5/16/2011 12:56:32 PM Info User "VisualCron Default Admin" - Set task state to: True 5/16/2011 12:56:32 PM Info Task started: download file (83) 5/16/2011 12:56:32 PM Debug Executing HTTP with parameters: 5/16/2011 12:56:37 PM Info Task completed: download file (83) 5/16/2011 12:56:37 PM Debug Setting previous task in TaskProcessCompleted: download file (5c28384e-edaf-4156-818c-77c4764d02d5) in job: _erik test 5/16/2011 12:56:37 PM Debug Process status - About to SendTaskProcess (83) 5/16/2011 12:56:37 PM Debug Process status - About to RemoveTaskProcess (83) 5/16/2011 12:56:37 PM Debug Client: 005257fb-ecb0-416f-8177-b3a9c188463c (10.5.107.16) has disconnected 5/16/2011 12:56:37 PM Debug Task (83) was removed from processlist: download file 5/16/2011 12:56:37 PM Debug Removed handlers for connection. 5/16/2011 12:56:37 PM Debug Entering RemoveConnection. 5/16/2011 12:56:37 PM Debug ConnClass picked up. 5/16/2011 12:56:37 PM Debug ConnClass deactivated. 5/16/2011 12:56:37 PM Debug Connection removed from dictionary. 5/16/2011 12:56:37 PM Debug Before sending ClientConnection. 5/16/2011 12:56:37 PM Debug Connection: 005257fb-ecb0-416f-8177-b3a9c188463c was removed 5/16/2011 12:56:37 PM Debug Job (75) was removed from processlist: _erik test 5/16/2011 12:56:37 PM Debug Next execution (2) for job '_erik test' is: 12:00:00 AM 5/16/2011 12:56:37 PM Info Job completed: _erik test Again a hit! --- Now a test without the devativate or activate in there: Code:5/16/2011 12:58:36 PM Debug TcpClient accepted. 5/16/2011 12:58:36 PM Debug Before sending ClientConnection. 5/16/2011 12:58:36 PM Debug Before returning sslStream 5/16/2011 12:58:36 PM Debug New client connected. 5/16/2011 12:58:36 PM Debug AuthenticateAsServer, certificate name: CN=vc 5/16/2011 12:58:36 PM Debug AuthenticateAsServer doneCN=vc 5/16/2011 12:58:36 PM Debug Waiting for client connection 5/16/2011 12:58:37 PM Debug Using normal logon (False) 5/16/2011 12:58:37 PM Info User "VisualCron Default Admin" (admin) - Logged in succesfully through Socket (a05d97ae-ee3f-4dec-821d-773e89e71a14) 5/16/2011 12:58:37 PM Debug Updating login status for: a05d97ae-ee3f-4dec-821d-773e89e71a14 5/16/2011 12:58:37 PM Debug Before sending ClientConnection. 5/16/2011 12:58:38 PM Comm IN: SERVERSETTINGSREQ 5/16/2011 12:58:38 PM Comm IN: LICENSEREQ Now my task isn't running anymore... donno why I have to put in an extra command to make it work. Regards Erik N.B. The client settings containing the log folder only contains the log_apiDATE.txt. The log_serverDATA.txt is in the application installation log folder. | Uses Visualcron since 2006. |
|
|
|
|
|
 Rank: Administration
Joined: 2/23/2008(UTC) Posts: 6,169  Location: Sweden Thanks: 200 times Was thanked: 120 time(s) in 115 post(s)
|
Some questions: 1. does it work when you do it locally instead of remotely? 2. when you connect, do you use set the sync parameter to "true" 3. if you wait some seconds after connecting before trying to run - does it work then? 4. does it make any difference if you turn of compression on remote connection? Edited by user Monday, May 16, 2011 2:04:29 PM(UTC)
| Reason: Not specified | |
|
|
|
|
|
 Rank: Advanced Member
Joined: 2/26/2008(UTC) Posts: 1,107  Location: Amsterdam, The Netherlands Thanks: 39 times Was thanked: 66 time(s) in 57 post(s)
|
1. If I do it locally, it works fine. (ConnectionType = Connection.ConnectionT.Local;) and running the app from the VC server. 2. Yes, I use the synchronizeServerObjects set to true during connect. 3. If I use the System.Threading.Thread.Sleep(5000) to wait for 5 seconds after connecting, my task isn't started. 4. If I set the UseCompression to false, my task isn't started.
Hope I can help with these answers.
Regards, Erik | Uses Visualcron since 2006. |
|
|
|
|
|
 Rank: Administration
Joined: 2/23/2008(UTC) Posts: 6,169  Location: Sweden Thanks: 200 times Was thanked: 120 time(s) in 115 post(s)
|
Took some time to debug this. The problem is that the Run method is not synchrous. So, if you are trying to run from a console app it is likely that the app exits before the message has been sent.
Preferably, we would make this method synchrous but we don't have time right now.
What you can do instead is to add an handler to TaskStarted event and exit when the Task has been started. I have a VB.NET example but you may also want to check that it was this particular Task that failed.
I am attaching the whole project. | |
|
|
|
|
|
 Rank: Newbie
Joined: 5/15/2011(UTC) Posts: 2 Location: Sydney, Australia
|
Right, that explains it
I have implemented checking for the task status/state to change and this is working very well
Thankyou very much support...
Case closed...
|
|
|
|
|
|
 Rank: Advanced Member
Joined: 2/26/2008(UTC) Posts: 1,107  Location: Amsterdam, The Netherlands Thanks: 39 times Was thanked: 66 time(s) in 57 post(s)
|
Hi, Today I also tested this VB implementation in C#. Here is my code: Code:using VisualCron; using VisualCronAPI;
namespace GetJobResult { class Program { static bool TaskStarted = false; static Server s = new Server();
static void Main(string[] args) { Client c = new Client(); c.LogToFile = true; Connection conn = new Connection(); conn.UserName = "admin"; conn.PassWord = ""; conn.Port = 16444; conn.Address = "visualcronserver"; conn.ConnectionType = Connection.ConnectionT.Remote; try { s = c.Connect(conn, true); } catch (Client.ClientLoginFailedException ex) { Console.WriteLine(string.Format("\nError:\n{0}", ex.Message)); return; }
s.Processes.TaskProcessStarted += new Processes.DelegateTaskProcessStarted(Processes_TaskProcessStarted); s.Processes.TaskProcessEnded += new Processes.DelegateTaskProcessEnded(Processes_TaskProcessEnded); TaskClass ta = new TaskClass(); ta = s.Jobs.Tasks.Get("5c28384e-edaf-4156-818c-77c4764d02d5"); s.Jobs.Tasks.Run(ta, false);
while (!TaskStarted) { System.Threading.Thread.Sleep(100); }
c.Disconnect(s); }
static void Processes_TaskProcessEnded(ref Server server, VCTaskProcessClass pc) { TaskClass tc = s.Jobs.Tasks.Get(pc.TaskId); Console.WriteLine(tc.Name + " was ended."); }
static void Processes_TaskProcessStarted(ref Server server, VCTaskProcessClass pc) { TaskClass tc = s.Jobs.Tasks.Get(pc.TaskId); Console.WriteLine(tc.Name + " was started."); TaskStarted = true; } } } This code works fine and the task runs everytime. I find it scary though to use the while loop here, it could be an infinite loop... Regards, Erik | Uses Visualcron since 2006. |
|
|
|
|
|
 Rank: Administration
Joined: 2/23/2008(UTC) Posts: 6,169  Location: Sweden Thanks: 200 times Was thanked: 120 time(s) in 115 post(s)
|
Nice, looks like my code | |
|
|
|
|
|
| Users browsing this topic |
|
Guest
|
VisualCron
»
Support
»
API
»
How to run a task using API
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.
|
|