This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

M-Files Configuration Frequency Interval

I am working on setting up something in my configuration that includes a RecurringOperationConfiguration

I have it working for schedule without any issue but when I try and lookup Interval it seems a bit vague and I don't really understand what the Time Value in the configuration is for.

It says it is configurable but I don't quite understand how to control the interval from the admin if it's giving me a Time Value. I've ready the following and haven't clued in on what I should be doing to allow the admin to decide what the interval should be/

https://developer.m-files.com/Frameworks/Vault-Application-Framework/Task-Queues/Recurring-Tasks/

What do I need to do for the admin to be able to set something like run every 2 hours?

Parents
  • Hi,

    The editor seems to render differently depending on...  Something.  Possibly your local PC settings.  In a lot of systems it renders as a 24-hour clock (which then makes more sense as an interval), but when it renders as an AM/PM time it's awkward.

    In your instance "every two hours" would be "2am".  Every 14 hours would be "2pm".  As I said: awkward.

    This hasn't come up as a significant issue thus far, but I will raise it with the VAF/configuration-editor team at some point to see whether there's a way we can force it to always be in 24-hour mode.

    Regards,

    Craig.

  • That is what we figured but additionally you cannot enter a 0 for the first hour so you cannot set an interval less than 1 hour with this issue.

  • This reply was deleted.
  • There's a lot to process here...  I was confused by the commented out code to start (e.g. the connection to the vault)...

    My gut instinct is that the job isn't completing successfully due to a timeout or similar.  I would suggest that you move to using an unsafe transaction processor, then update the objects one-by-one inside a transaction using the transaction runner.  You also need to add some logging (if using the VAF Extensions) and job update calls.

    Something like this, perhaps (COMPLETELY UNTESTED; I DIDN'T EVEN HAVE VISUAL STUDIO OPEN SO THERE MAY BE SOME TYPOS):

    [TaskProcessor(QueueId, POTimeLoopApp2, TransactionMode = TransactionMode.Unsafe)]
    public void POTimeLoop2(ITaskProcessingJob<TaskDirective> job)
    {	
    	// Sanity.
    	int classID = this.Configuration?.POTimeLoop?.POTimeLoop2Settings?.ClassToRunOn?.ID ?? -1;
    	int startStateID = this.Configuration?.POTimeLoop?.POTimeLoop2Settings?.StartWorkflowAndState?.State?.ID ?? -1;
    	int endStateID = this.Configuration?.POTimeLoop?.POTimeLoop2Settings?.StartWorkflowAndState?.State?.ID ?? -1;
    	int incrementProperty = this.Configuration?.POTimeLoop?.POTimeLoop2Settings?.IncrementPropertyInteger?.ID ?? -1;
    	if (!this.Configuration.POTimeLoop.POTimeLoop2Settings.Enabled)
    	{
    		this.Logger?.Info($"Skipped because task is disabled.");
    		job.Update(details: $"Skipped because task is disabled.");
    		return;
    	}
    	if(classID == -1
    		|| startStateID == -1
    		|| endStateID == -1)
    	{
    		this.Logger?.Warn($"Skipped because config invalid.");
    		job.Update(details: $"Skipped because config invalid.");
    		return;
    	}
    	
    	// Skip days we don't want to do.
    	{
    		string today = System.DateTime.Now.ToString("dddd");
    		if ((today == "Saturday" || today == "Sunday" || today == "Samedi" || today == "Dimanche") && this.Configuration.POTimeLoop.POTimeLoop2Settings.SkipWeekends)
    		{
    			// Skip.
    			this.Logger?.Info($"Skipped because it's a weekend and config says to skip weekends.");
    			job.Update(details: $"Skipped because it's a weekend and config says to skip weekends.");
    			return;
    		}
    	}
    	
    	// Search for the objects.
    	MFSearchBuilder poTimeLoopSearch = new MFSearchBuilder(transactionalVault);
    	poTimeLoopSearch.Deleted(false);
    	poTimeLoopSearch.Class(this.Configuration.POTimeLoop.POTimeLoop2Settings.ClassToRunOn.ID);
    	poTimeLoopSearch.Property(39, MFDataType.MFDatatypeLookup, this.Configuration.POTimeLoop.POTimeLoop2Settings.StartWorkflowAndState.State.ID);
    	var results = poTimeLoopSearch.Find();
    	
    	// Get the transaction runner.
    	var transactionRunner = this.GetTransactionRunner();
    	
    	// Iterate over them and update one by one in a transaction.
    	this.Logger.Debug($"There were {results.Count} items returned.");
    	job.Update(percentComplete: 0, details: $"There were {results.Count} items returned.");
    	for (int i = 1; i <= results.Count; i++)
    	{
    		transactionRunner.Run((transactionalVault) =>
    		{
    			ObjVerEx objectToLoop;
    			try
    			{
    				// Attempt to load the object.
    				this.Logger.Trace($"Processing {results[i].ObjVer}.");
    				objectToLoop = new ObjVerEx(transactionalVault, results[i].ObjVer);
    				this.Logger.Debug($"Processing {objectToLoop}.");
    				job.Update(percentComplete: (i-1) * 100 / results.Count, details: $"Processing {objectToLoop}.");
    
    				PropertyValues properties = new PropertyValues();
    				
    				// WHAT IS NEWOBJECT?!
    				var propertyValue = newObject.createPropertyValueInt(this.Configuration.POTimeLoop.POTimeLoop2Settings.IncrementPropertyInteger.ID, 1);
    				
    				//if the increment is not empty, increase it by 1 and change the state
    				if (objectToLoop.GetProperty(this.Configuration.POTimeLoop.POTimeLoop2Settings.IncrementPropertyInteger.ID).TypedValue.DisplayValue != "")
    				{
    					int incrementValue = Int32.Parse(objectToLoop.GetProperty(this.Configuration.POTimeLoop.POTimeLoop2Settings.IncrementPropertyInteger.ID).TypedValue.DisplayValue);
    					incrementValue++;
    					propertyValue.Value.SetValue(MFDatatype.MFDatatype.Integer, incrementValue);
    				}
    				
    				// Set the properties and update the object.
    				properties.Add(-1, propertyValue);
    				properties.Add(-1, newObject.createPropertyValueLookup(39, this.Configuration.POTimeLoop.POTimeLoop2Settings.EndWorkflowAndState.State.ID));
    				objectToLoop.SaveProperties(properties);
    			}
    			catch(Exception e)
    			{
    				this.Logger.Error(e, $"Could not process object {objectToLoop}.");
    				job.Update(details: $"Failed to process {objectToLoop}: {e.Message}");
    			}
    		}
    	}
    }

    You may also be able to clean up some of that configuration too (e.g. use a search conditions editor rather than hard-coding the filter logic), but I've not looked at that properly.

  • Hey Craig,

    I've had to comment out the logger pieces as we have had complications updating to the newest versions of the VAF.Extensions but my main issue after fixing some things is that your code doesn't seem to provide a reference to transactional vault? How do I resolve this?

  • In this scenario you would use the "env.Vault" (non-transactional vault reference) for reading.

  • How does one get env when env is not passed into a TaskProcessor?

    I did resolve the reference to the transactionalVault but I am not really sure what will happen until I run it:

  • Sorry, I apologise.  The job has a vault reference: job.Vault.

    I should acknowledge to myself that I cannot reply to posts as well as doing other things.  The job vault reference for an unsafe transaction processor is a non-transactional vault reference.

  • So using those changes I get this:

  • What version of the Extensions are you using?  What issues did you get upgrading?  That could well be the underlying issue.

    That said: you need to check the logic in my implementation.  As I said: it was written in Notepad (hence the issue with the transactional vault), so maybe I've made a mistake.

  • I am doing some additional testing, your messages into the console are very insightful and providing me with some good debugging(something I will be using in the future). The mistake was mine in this case.

    As far as the update is concerned some of the reliance on other packages we could never get our applications to build properly as there wasn't a version that was acceptable on NuGet. Ultimately we had to roll back because of incompatibilities. 

  • If you ever try this again then I would be interested in exactly what caused you an issue.  You are missing out on some good functionality by being stuck with older VAF Extensions releases.

Reply Children
  • I spent a good day on it trying to get the packages I needed, a lot of the issue was related to Logging specifically. Incompatible versions etc.

    I just ran it again and it looks like it stopped after one run:

    Looks like if I make any changes to the configuration it then schedules another instance but only runs once then stops.

  • Have you tried using System.Diagnostics.Debugger.Launch to attach a debugger when the task is processed, and step through it?

  • You could also add a job.Update call after the loop to see whether it thinks it finished properly.

  • I added an update after it all to see if it completes properly. I should add that it completes the job successfully(changes the workflow/state) and always has, just never runs again. 

    Also I see your comment in my code referring to "newObject", it's a class I wrote years ago to facilitate creating propertyValues and Objects, nothing special. 

    Looks like it completes without any issues:

    I've got that line right at the bottom of the function:

  • My suspicion is that this is a bug in an older release.

  • I'll spend a bit of time fighting with updating the code base, want anything I run into posted here?

  • So after running an update in NuGet I run into this exception when installing the application after building. This is what we ran into previously too, after building successfully it won't install.

    DlgClientApplications.cpp, 539, Starting the application "ConformityVaultApplication (1.6.7)" failed. (0x80040120)
    Item_DocumentVault.cpp, 1780, Starting the application "ConformityVaultApplication (1.6.7)" failed. (0x80040120)
    RPCMethodCallWithRetry.h, 151, Starting the application "ConformityVaultApplication (1.6.7)" failed. (0x80040120)
    RPCMethodCallWithRetry.h, 151, Starting the application "ConformityVaultApplication (1.6.7)" failed. (0x80040120)
    RPCClientScript.cpp, 1021, Starting the application "ConformityVaultApplication (1.6.7)" failed. (0x80040120)
    RPCClientScript.cpp, 406, Starting the application "ConformityVaultApplication (1.6.7)" failed. (0x80040120)
    RPCClientScriptHelper.cpp, 625, Starting the application "ConformityVaultApplication (1.6.7)" failed. (0x80040120)
    RPCClientScriptHelper.cpp, 1159, Starting the application "ConformityVaultApplication (1.6.7)" failed. (0x80040120)
    RPCClientScriptHelper.cpp, 1722, Starting the application "ConformityVaultApplication (1.6.7)" failed. (0x80040120)
    ExtensionManager.cpp, 648, Starting the application "ConformityVaultApplication (1.6.7)" failed. (0x80040120)
    ExtensionManager.cpp, 648, Exception has been thrown by the target of an invocation. (0x80131604)
    ExtensionManager.cpp, 782, Exception has been thrown by the target of an invocation. (0x80131604)
    ExtObjectPlatform.cpp, 177, Exception has been thrown by the target of an invocation. (0x80131604)
    ExtObjectPlatform.cpp, 439, Exception has been thrown by the target of an invocation. (0x80131604)
    CoMFAppPlatform.cpp, 322, Exception has been thrown by the target of an invocation. (0x80131604)
    CoDynamicCLRObjectWrapper.cpp, 127, Exception has been thrown by the target of an invocation. (0x80131604)
    ManagedError.cpp, 150, Exception has been thrown by the target of an invocation. (0x80131604)
    mscorlib: [CManagedError* CRuntimeObjectWrapper.InitAndCreateObject(CRuntimeObjectWrapper*, CManagedError*, Char**, Char**)], IL:45, Exception has been thrown by the target of an invocation. (0x80131604)
    mscorlib: [System.Object CreateInstance(System.Type)], IL:0, Exception has been thrown by the target of an invocation. (0x80131604)
    mscorlib: [System.Object CreateInstance(System.Type, Boolean)], IL:58, Exception has been thrown by the target of an invocation. (0x80131604)
    mscorlib: [System.Object CreateInstanceSlow(Boolean, Boolean, Boolean, System.Threading.StackCrawlMark ByRef)], IL:106, Exception has been thrown by the target of an invocation. (0x80131604)
    mscorlib: [System.Object CreateInstance(System.RuntimeType, Boolean, Boolean, Boolean ByRef, System.RuntimeMethodHandleInternal ByRef, Boolean ByRef)], IL:-1, Exception has been thrown by the target of an invocation. (0x80131604)
    VaultApplication.cs, 31 (IL:17), The type initializer for 'MFiles.VaultApplications.Logging.LogManager' threw an exception. (0x80131534)
    MFiles.VaultApplications.Logging: [Void .ctor()], IL:49, The type initializer for 'MFiles.VaultApplications.Logging.LogManager' threw an exception. (0x80131534)
    ConfigurableVaultApplicationBase.cs, 46 (IL:17), The type initializer for 'MFiles.VaultApplications.Logging.LogManager' threw an exception. (0x80131534)
    MFiles.VaultApplications.Logging: [MFiles.VAF.Configuration.SecureConfigurationManager`1[TSecureConfiguration] GetConfigurationManager()], IL:28, The type initializer for 'MFiles.VaultApplications.Logging.LogManager' threw an exception. (0x80131534)
    MFiles.VaultApplications.Logging: [Void .ctor(Boolean, System.Resources.ResourceManager[])], IL:7, The type initializer for 'MFiles.VaultApplications.Logging.LogManager' threw an exception. (0x80131534)
    MFiles.VaultApplications.Logging: [Void .ctor(Boolean)], IL:0, The type initializer for 'MFiles.VaultApplications.Logging.LogManager' threw an exception. (0x80131534)
    MFiles.VaultApplications.Logging: [MFiles.VaultApplications.Logging.ILogger GetLogger(System.Type, MFiles.VaultApplications.Logging.ILoggingContext)], IL:0, The type initializer for 'MFiles.VaultApplications.Logging.LogManager' threw an exception. (0x80131534)
    MFiles.VaultApplications.Logging: [Void .cctor()], IL:5, Method not found: 'Void NLog.Config.LoggingConfiguration.AddRule(NLog.LogLevel, NLog.LogLevel, NLog.Targets.Target, System.String, Boolean)'. (0x80131513)
    MFiles.VaultApplications.Logging: [Void UpdateConfiguration(MFiles.VaultApplications.Logging.NLog.NLogLoggingConfiguration)], IL:-1, Method not found: 'Void NLog.Config.LoggingConfiguration.AddRule(NLog.LogLevel, NLog.LogLevel, NLog.Targets.Target, System.String, Boolean)'. (0x80131513)
    (M-Files 22.9.11816.9 2022-09-27T14:46:39.729Z)

  • Yes.  I'm happy to help.  Want to give it a go and if you have problems then either post here or, if it's complex, drop me an email and we'll arrange a suitable time for a call?

  • I ran into the following error after building and then attempting to install(so this happened when installing the application):

    DlgClientApplications.cpp, 539, Starting the application "ConformityVaultApplication (1.6.7)" failed. (0x80040120)
    Item_DocumentVault.cpp, 1780, Starting the application "ConformityVaultApplication (1.6.7)" failed. (0x80040120)
    RPCMethodCallWithRetry.h, 151, Starting the application "ConformityVaultApplication (1.6.7)" failed. (0x80040120)
    RPCMethodCallWithRetry.h, 151, Starting the application "ConformityVaultApplication (1.6.7)" failed. (0x80040120)
    RPCClientScript.cpp, 1021, Starting the application "ConformityVaultApplication (1.6.7)" failed. (0x80040120)
    RPCClientScript.cpp, 406, Starting the application "ConformityVaultApplication (1.6.7)" failed. (0x80040120)
    RPCClientScriptHelper.cpp, 625, Starting the application "ConformityVaultApplication (1.6.7)" failed. (0x80040120)
    RPCClientScriptHelper.cpp, 1159, Starting the application "ConformityVaultApplication (1.6.7)" failed. (0x80040120)
    RPCClientScriptHelper.cpp, 1722, Starting the application "ConformityVaultApplication (1.6.7)" failed. (0x80040120)
    ExtensionManager.cpp, 648, Starting the application "ConformityVaultApplication (1.6.7)" failed. (0x80040120)
    ExtensionManager.cpp, 648, Exception has been thrown by the target of an invocation. (0x80131604)
    ExtensionManager.cpp, 782, Exception has been thrown by the target of an invocation. (0x80131604)
    ExtObjectPlatform.cpp, 177, Exception has been thrown by the target of an invocation. (0x80131604)
    ExtObjectPlatform.cpp, 439, Exception has been thrown by the target of an invocation. (0x80131604)
    CoMFAppPlatform.cpp, 322, Exception has been thrown by the target of an invocation. (0x80131604)
    CoDynamicCLRObjectWrapper.cpp, 127, Exception has been thrown by the target of an invocation. (0x80131604)
    ManagedError.cpp, 150, Exception has been thrown by the target of an invocation. (0x80131604)
    mscorlib: [CManagedError* CRuntimeObjectWrapper.InitAndCreateObject(CRuntimeObjectWrapper*, CManagedError*, Char**, Char**)], IL:45, Exception has been thrown by the target of an invocation. (0x80131604)
    mscorlib: [System.Object CreateInstance(System.Type)], IL:0, Exception has been thrown by the target of an invocation. (0x80131604)
    mscorlib: [System.Object CreateInstance(System.Type, Boolean)], IL:58, Exception has been thrown by the target of an invocation. (0x80131604)
    mscorlib: [System.Object CreateInstanceSlow(Boolean, Boolean, Boolean, System.Threading.StackCrawlMark ByRef)], IL:106, Exception has been thrown by the target of an invocation. (0x80131604)
    mscorlib: [System.Object CreateInstance(System.RuntimeType, Boolean, Boolean, Boolean ByRef, System.RuntimeMethodHandleInternal ByRef, Boolean ByRef)], IL:-1, Exception has been thrown by the target of an invocation. (0x80131604)
    VaultApplication.cs, 31 (IL:17), The type initializer for 'MFiles.VaultApplications.Logging.LogManager' threw an exception. (0x80131534)
    MFiles.VaultApplications.Logging: [Void .ctor()], IL:49, The type initializer for 'MFiles.VaultApplications.Logging.LogManager' threw an exception. (0x80131534)
    ConfigurableVaultApplicationBase.cs, 46 (IL:17), The type initializer for 'MFiles.VaultApplications.Logging.LogManager' threw an exception. (0x80131534)
    MFiles.VaultApplications.Logging: [MFiles.VAF.Configuration.SecureConfigurationManager`1[TSecureConfiguration] GetConfigurationManager()], IL:28, The type initializer for 'MFiles.VaultApplications.Logging.LogManager' threw an exception. (0x80131534)
    MFiles.VaultApplications.Logging: [Void .ctor(Boolean, System.Resources.ResourceManager[])], IL:7, The type initializer for 'MFiles.VaultApplications.Logging.LogManager' threw an exception. (0x80131534)
    MFiles.VaultApplications.Logging: [Void .ctor(Boolean)], IL:0, The type initializer for 'MFiles.VaultApplications.Logging.LogManager' threw an exception. (0x80131534)
    MFiles.VaultApplications.Logging: [MFiles.VaultApplications.Logging.ILogger GetLogger(System.Type, MFiles.VaultApplications.Logging.ILoggingContext)], IL:0, The type initializer for 'MFiles.VaultApplications.Logging.LogManager' threw an exception. (0x80131534)
    MFiles.VaultApplications.Logging: [Void .cctor()], IL:5, Method not found: 'Void NLog.Config.LoggingConfiguration.AddRule(NLog.LogLevel, NLog.LogLevel, NLog.Targets.Target, System.String, Boolean)'. (0x80131513)
    MFiles.VaultApplications.Logging: [Void UpdateConfiguration(MFiles.VaultApplications.Logging.NLog.NLogLoggingConfiguration)], IL:-1, Method not found: 'Void NLog.Config.LoggingConfiguration.AddRule(NLog.LogLevel, NLog.LogLevel, NLog.Targets.Target, System.String, Boolean)'. (0x80131513)
    (M-Files 22.9.11816.9 2022-09-27T14:46:39.729Z)

  • We will have to communicate via email or another way(teams maybe?) since the forum is flagging my posts with an error message I am running into as spam. I will send an email your way.