SOLIDWORKS PDM API: Scheduling a task that requires user input?

So everyone knows you can schedule task to run at specific time. Awesome feature. A lot of people would schedule tasks to run during non-business hours. This means the task launches and runs completely unattended.

This works fine if the task does not require user input but what if it does? The problem with the current architecture is that your TaskLaunch is only triggered when it’s time to launch the task.

I think SW should add a new hook called OnTaskSchedule where the user is able to provide the task with some input. This can take occur is the task is immediately scheduled and serve as a replacement for TaskLaunch.

Thoughts?

1 Like

I agree.

Start an enhancement request so we can vote for it.

When the task setup window loads you can cache the stored scheduling info to RAM. When you call TaskSetupButton you could then compare the newly entered data to RAM to see if it changed. If it did call a custom routine for input and store to a DataDictionary.

That is, if you can read scheduling data from the API… if not, you’d have to check the SQL tables programmatically to do this.

@Torquin : Welcome to the forum ! :smiley:

That’s a great approach. The only issue with this approach, if you don’t mind me saying, is that in order for you to add user input to the task, you need to edit the task definition. I don’t think the user that is launching the task is meant to do that (or needs to).

Adding logic to manage tasks in the task definition (via IEdmTaskProperties.SetValEx and GetValEx) is not something I want to do that. It kind of defeats the point of the task list.

Thoughts?

Thanks!

I appreciate the feedback. I guess I am not familiar with a way to schedule a task outside of editing the task definition (to get to the scheduling page). So in my eyes, there really isn’t another option. But maybe I just didn’t know of other ways.

I’m not sure I’m following what exactly you would like. This is what I think I’m reading:
You want the admin to schedule a task to run on client PCs. This task would startup and run perhaps while the user is active on the workstation or perhaps when they are away on break or something. You want a chance to program in a pop-up to get user input for this scheduled task.

Forgive me for bad example, its just fresh in my mind, but this reminds me a bit of Windows update. I haven’t restarted my PC like I should and windows took the liberty of scheduling a restart, thankfully it popped up for user input of when to do this restart.

Or do you want the user to be able to schedule a task at a later point?

Maybe you have an example usage?

Here’s an example:

Background: Archive server and db server are hosted on the cloud. Data transfer from the client to the server takes a long time (+200 MB).

Observation: Transferring files on the actual server to PDM is faster.

Solution: Develop a task add-in where a PDM user can schedule the task to run on the server. The user needs to specify a source folder and a target folder on PDM each time they schedule a task.

So the user is initiating the task as opposed to a fixed schedule set by admin? Does the user need to schedule the task to occur at a specific time or should it run as soon as they provide the to and from directories?

Yes to first question.
Task occur at a specific time.

I see. So you would need to use some other scheduling service to run the file copy based on user input from a regular menu launch. Doable but messy I suppose.

1 Like

Agree! Messy but it makes sense for the user.

I’ve read that spawning another process (not thread) from a task is discouraged, but can a PDM task write a script and schedule a windows task to call that script at a set time?

Would be nice to just use PDM’s scheduler.

Can you do me a favor and link that thread here? We’re spinning new sw processes left and right here with no issues…
Thanks!

1 Like

Good question with a good point.

I am sorry, I don’t have a link. I think the context that I maybe should have eluded to is that it’s discouraged unless the programmer understands all that could happen and how to prevent it from causing serious effects. The suggestion was made to me, who has little experience in PDM API. The point being made was there is a bit of safety net if the scope of the task is limited to PDM and spawning other processes from a task opens the door to another layer of responsibility.
If I recall correctly the specific case was concerning asynchronous actions to prevent blocking of the transition. The problem with running actions in other process is that the state of the file(s) in PDM (not specifically workflow state) can no longer be assumed from the info provided in the task data objects. It would be possible for the spawned process to attempt to perform actions based on old information, or it would need to know what all to check. Also what all could happen if another task starts up another instance of the same process before the first one is finished if they are somehow interrelated? There is some benefit of the structure of one task finishing before the next one is ran.

So it was discouraged to me, not prohibited, and shouldn’t be used unless there’s a good reason to do so and an understanding of all the ways it could go off the rails.

2 Likes

So the scheduling feature of the task does not allow for user input (apart from the Admin entries in the task setup page).

If you need a user to provide input, you could use a simple right click add-in menu to pop a GUI where they enter the relevant info. This is saved to a database (or data dictionary) that a scheduled task is monitoring periodically.

Anytime the scheduled task sees new updates to process it goes ahead to do those tasks.

Prolly the right way to go about this…