Skip to content

Recurring jobs

invoiceR performs many tasks on a schedule in the background: collecting the mailbox, synchronizing master data, handing documents over to the ERP, importing users and much more. These recurring jobs (also called cron jobs) are run by the Hangfire component.

  • Administration > Job-Ausführung lists all configured jobs with their schedule (Cron), next and last run. Run Task starts a job immediately.
  • Administration > Hangfire dashboard shows details: history, logs of each run and failed jobs.
Job-Ausführung page with the list of jobs, columns Id, Job, Cron and the Run Task button

Both menu items are only visible with the corresponding permissions.

Each job is an entry in the table conf.IrRecurringJobs:

ColumnMeaning
IdGUID of the entry.
TenantIdTenant.
Enabled1 = the job is active.
HangfireIdUnique technical name, for example ch.invoicer.tool.delete.files.
DescriptionLabel shown in the job list and in Hangfire.
CronExpressionSchedule in cron format, for example 0 6 * * * for daily at 6 am.
ClassIdentifierFull class name of the job in invoiceR or a plugin.
MethodNameMethod that is started.
MethodArgumentIdentifierClass name of the configuration into which Configuration is read.
ConfigurationJSON with the job settings.
EnvironmentFilterEmpty: always applies. Otherwise only in the named environments, for example Production.
VisibleFilterRoleId, EditFilterRoleIdOptional. Role allowed to see or edit the job.
SequenceCode, SequenceOrderOptional, for batch jobs (see below).
ObjectMappingCodeOptional, only used by some jobs.

Changes to the table only take effect after the job Wiederkehrende Hangfire-Jobs anmelden (ID ch.invoicer.fix.setupRecurringJobs) has run. It runs once a day on its own; after a change, start it by hand under Administration > Job-Ausführung or in the Hangfire dashboard. It re-registers all active jobs and removes jobs that are no longer configured.

If several jobs must always run one after the other (for example first import master data, then export documents), group them into a batch:

  • SequenceCode: the same number for all jobs of the batch.
  • SequenceOrder: order within the batch.

The batch appears as its own job BatchJob_<SequenceCode> and uses the schedule of the first job. The CronExpression of the other jobs in the batch is ignored.

Deletes old files in a folder on the invoiceR server, for example temporary import files. Files can first be moved to an archive subfolder and deleted later.

ColumnValue
ClassIdentifierenio.tool.Plugin.FileDeleter.FileDeleter
MethodNameCheckFiles
MethodArgumentIdentifierenio.tool.Plugin.FileDeleter.FileDeleterArgument
{
"FolderPath": "D:\\invoiceR\\Import",
"MoveToArchiveAfterXDays": 14,
"DeleteFromArchiveAfterXDays": 40,
"DirectDeleteAfterXDays": null,
"ArchiveFolderName": "Archive",
"AddTimestampInArchiveFileName": true
}
KeyMeaning
FolderPathAbsolute path of the folder on the invoiceR server.
MoveToArchiveAfterXDaysAfter this many days without change, a file moves to the archive folder.
DeleteFromArchiveAfterXDaysAfter this many days without change, a file in the archive folder is deleted.
DirectDeleteAfterXDaysIf set, files are deleted directly after this many days, without the archive folder.
ArchiveFolderNameName of the archive subfolder (default Archive).
AddTimestampInArchiveFileNametrue adds the last modification date to the file name when moving.

Regularly runs an SQL statement on the invoiceR database, for example a stored procedure for clean-up work.

ColumnValue
ClassIdentifierenio.tool.Plugin.SqlExecutor.ExecuteSqlStatement
MethodNameRunSql
MethodArgumentIdentifierenio.tool.Plugin.SqlExecutor.ExecuteSqlStatementArgument
{
"StatementDescription": "Starts the procedure dbo.MyCleanup",
"SqlContent": "EXEC [dbo].[MyCleanup]",
"NumberOfRowsAffectedForNoError": -1
}
KeyMeaning
StatementDescriptionDescription shown in the log.
SqlContentSQL to run. Move longer logic into a stored procedure.
NumberOfRowsAffectedForNoErrorExpected number of affected rows. If it does not match, the job fails. -1 turns the check off.
CommandTimeoutOptional. Time limit in seconds for long statements (default 1800).

Imports monthly average rates from the Federal Office for Customs and Border Security (FOCBS, German BAZG) and updates the exchange rates in invoiceR.

ColumnValue
ClassIdentifierenio.tool.Plugin.CurrencyExchangeRateImport.CurrencyExchangeRateImport
MethodNameDoImport
MethodArgumentIdentifierenio.tool.Plugin.CurrencyExchangeRateImport.CurrencyExchangeRateImportArgument
{
"Xmlurl": "https://www.backend-rates.bazg.admin.ch/api/xmlavgmonth",
"FilterCurrencies": ["USD", "EUR"]
}
KeyMeaning
XmlurlAddress of the XML file with the FOCBS rates.
FilterCurrenciesCurrencies to update. Empty: all currencies.
INSERT INTO conf.IrRecurringJobs
(Id, TenantId, Enabled, HangfireId, Description, CronExpression,
ClassIdentifier, MethodName, MethodArgumentIdentifier, Configuration)
VALUES
(NEWID(), 1, 1, N'ch.invoicer.tool.delete.files', N'Clean up import files', N'5 3 * * *',
N'enio.tool.Plugin.FileDeleter.FileDeleter', N'CheckFiles',
N'enio.tool.Plugin.FileDeleter.FileDeleterArgument',
N'{ "FolderPath": "D:\\invoiceR\\Import", "DirectDeleteAfterXDays": 30 }');

Then start Wiederkehrende Hangfire-Jobs anmelden.