交易优先级? [英] Transaction priority?

查看:124
本文介绍了交易优先级?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道每3分钟运行一次脚本,脚本包含的功能是什么:

I have crons what run script each 3 minutes, script contains function what:

try
   begin transaction
   loop
     //parse large xml data
     //send data to database
   endloop
   commit
endtry
catch
   rollback
endcatch

现在,数据插入是一个漫长的过程,大约需要3到6分钟,而cron则是每个3分钟,因此有时会出现过程冲突. 我看到当我在循环内添加提交时,优先级具有新流程,我能以某种方式说嘿新事务等到事务提交之前吗?

Now, data insertion is long process what takes about 3-6 minutes, and cron is each 3 minutes, so there is sometimes process conflict. I see when i add commit inside loop that priority has new process, can i somehow say hey new transaction wait until before transaction commit?

推荐答案

我会尝试保持简单.....,并在现有cron脚本的顶部使用类似这样的简单文件锁定过程.

I would try and Keep It Simple S....., and use a simple file locking process like this at the top of your existing cron script.

$fp = fopen("/tmp/my_cron_lock.txt", "r+");

if ( ! flock($fp, LOCK_EX)) {
    // other cron is overrunning so
    // I'll get restarted in 3 mins 
    // so I will let other job finish

    fclose($fp);

    exit;
}

// existing script



// free the lock, 
// although this will happen automatically when script terminates

    fclose($fp);
?>

这篇关于交易优先级?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆