face-it/Hangfire.Tags

Searching by tag throws exception when tag matches existing jobId

Closed this issue · 1 comments

Consider an existing job with the ID 125462.
Searching by tag with the value 125462 (or using the URI ".../hangfire/tags/search/125462") returns the following error message:
{"Message":"Exception has been thrown by the target of an invocation.\r\nError converting data type nvarchar to bigint."}

I thought this was gonna be an easy change, but alas. Due to the nature of how things are stored internally, there is no easy solution.

When adding a tag, two sets are added or updated in the database:

  • One set with the tagname as key and one or more background job ids as value
  • One set with the background job id as key and one or more tagnames as value

If background job id and tagname are identical, the key value for both sets will be identical, which results in a combined set. We should've made a difference between the used keynames, but can't do that anymore without messing up existing installations.

So, currently I've updated the SQL and Postgres providers to filter for numeric values, the Redis providers to filter for unique identifiers (UUID) values, however, one issues might remain in the Redis providers: if a job has multiple tags, the amount of jobs for a specific tag will be the total amount of tags.

In general: our projects never use the datatype for the storage provider as tag, but we always prefix these manually. In your case, I would suggest using the tag job-.