Making Tasks atomic transactions by default

  • 7 August 2020
  • 0 replies
  • 58 views

Userlevel 6
Badge +18

Goal

Tasks are many times a sort of transaction and should rollback any changes it made during it's execution if anything goes wrong. The Software Factory currently doesn’t automatically make the task atomic.

Solution

Create the tag in ‘Projects → Full model → Tag’ and add a Dynamic model record with the code. Upon generating the definition, all tasks without the tag will be made atomic and all tasks with the tag will not be atomic.

Code:

-- Set single transaction (atomic) on when not exists as tag.
update t
set    t.single_transaction = 1
from   task t
where  t.project_id         = @project_id
  and  t.project_vrs_id     = @project_vrs_id
  and  t.task_type_id       = 'STORED_PROCEDURE'
  and  t.single_transaction = 0
  and not exists (
                  select 1
                  from   task_tag tt
                  where  tt.project_id     = t.project_id
                    and  tt.project_vrs_id = t.project_vrs_id
                    and  tt.tag_id         = 'TASK_NOT_ATOMIC'
                    and  tt.task_id        = t.task_id
                 )
-- Set single transaction (atomic) off when  exists as tag.
update t
set    t.single_transaction = 0
from   task t
where  t.project_id         = @project_id
  and  t.project_vrs_id     = @project_vrs_id
  and  t.task_type_id       = 'STORED_PROCEDURE'
  and  t.single_transaction = 1
  and  exists (
               select 1
               from   task_tag tt
               where  tt.project_id     = t.project_id
                 and  tt.project_vrs_id = t.project_vrs_id
                  and  tt.tag_id         = 'TASK_NOT_ATOMIC'
                  and  tt.task_id        = t.task_id
               )

 


0 replies

Be the first to reply!

Reply