Hangfire icon indicating copy to clipboard operation
Hangfire copied to clipboard

Use constant value for StateName

Open u1-liquid opened this issue 4 years ago • 2 comments

Use constant value for StateName.

With this, StateClass.StateName could be used in switch-case statement.

u1-liquid avatar Dec 08 '20 05:12 u1-liquid

static readonly fields are evaluated at runtime when const — at compile time.

If state names are constants and if at some point a constant value is changed, it will require every Hangfire consumer to rebuild their code for these changes to take effect.

On the other hand, consumers will not have to do anything if it is a readonly field.

Frazi1 avatar Dec 08 '20 08:12 Frazi1

The state names are already stored into storage constantly, so if some point that value is changed, it means other consumers couldn't fetch jobs correctly until rebuild their codes for those changes to take effect.

I think there is no advantages about this point to keep StateName field to static readonly.

Also, this changes only affects to Hangfire.Core, So basically users who uses this library will NOT changes this part of codes, If they need to change this kind of values, the state class should be defined in their code, which is not affected by this change.

static readonly fields are evaluated at runtime when const — at compile time.

If state names are constants and if at some point a constant value is changed, it will require every Hangfire consumer to rebuild their code for these changes to take effect.

On the other hand, consumers will not have to do anything if it is a readonly field.

u1-liquid avatar Dec 08 '20 08:12 u1-liquid