Skip to content

Instantly share code, notes, and snippets.

@martinferreira
Last active May 17, 2017 08:08
Show Gist options
  • Save martinferreira/f82d8a79485854ec72a90608ebc38e0f to your computer and use it in GitHub Desktop.
Save martinferreira/f82d8a79485854ec72a90608ebc38e0f to your computer and use it in GitHub Desktop.
17790 : AC: Prototype automation of one off jobs for trident deploys
BEGIN
DECLARE @InvocationData VARCHAR(500)
SET @InvocationData = '{"Type":"Lightstone.Trident.Api.Jobs.ElasticSearchRebuildIndexes, Lightstone.Trident.Api, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null","Method":"RebuildIndexes","ParameterTypes":"[]","Arguments":"[]"}'
INSERT into [HangFire].[Job] (StateId, StateName, InvocationData, Arguments, CreatedAt, ExpireAt) values (NULL, 'Enqueued', @InvocationData,'[]', GETUTCDATE(), NULL)
DECLARE @JobId int
select @JobId=id from [HangFire].[Job] where statename = 'Enqueued' and invocationdata = @InvocationData and StateId is null
INSERT into [HangFire].[State] ( JobId, Name, Reason, CreatedAt, Data) values
( @JobId, 'Enqueued', NULL, GETUTCDATE(), '{"EnqueuedAt":"' + (CONVERT(VARCHAR,GETUTCDATE(), 120))+'","Queue":"default"}')
DECLARE @StateId int
SELECT @StateId = id from [HangFire].[State] Where JobId = @JobId
UPDATE [HangFire].[Job] SET StateId = @StateId where Id = @JobId
INSERT INTO [HangFire].[JobQueue] (JobId, Queue) VALUES (@JobId, 'default')
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment