首页 \ 问答 \ 在redis队列上处理事务(Handle transactions on redis queue)

在redis队列上处理事务(Handle transactions on redis queue)

我在一个函数中有多个任务,我使用函数中的事务
我想为这个事务性任务使用redis队列
例如,我有一个像下面这样的函数:

 private function  check_destination_delivered($request,$id,$order)
{
    if ($request->get('status') == 'destination_delivered')
    {
      $this->destination_verification($request);
      DB::beginTransaction();
      try
      {
        $this->calculate_credit($id,$order);
        $this->calculate_customer_gift_credit($id,$order);
        DB::commit();
      }
      catch (\Exception $e)
      {
        DB::rollback();
        return $this->respondUnprocessable(1180,'error', $e);
      }
    }
}

在这个功能我想要这一行

$this->destination_verification($request);

在事务开始之前运行,并在此之后:

    $this->calculate_credit($id,$order);
    $this->calculate_customer_gift_credit($id,$order);

使用redis队列计算几个小时后,并使用事务处理来完成每个任务,如果某些任务失败,则再次运行直到所有要完成的任务


I have multiple tasks in a function and i use transaction in function
I want to use redis queue for this transactional tasks
For example i have a function like below :

 private function  check_destination_delivered($request,$id,$order)
{
    if ($request->get('status') == 'destination_delivered')
    {
      $this->destination_verification($request);
      DB::beginTransaction();
      try
      {
        $this->calculate_credit($id,$order);
        $this->calculate_customer_gift_credit($id,$order);
        DB::commit();
      }
      catch (\Exception $e)
      {
        DB::rollback();
        return $this->respondUnprocessable(1180,'error', $e);
      }
    }
}

In this function i want to this line

$this->destination_verification($request);

Run before transaction begin and after that this lines :

    $this->calculate_credit($id,$order);
    $this->calculate_customer_gift_credit($id,$order);

Use redis queue to calculate a few hours later and use transaction to every task in there to be done and if some tasks be fail .queue run again until all tasks to be done


原文:https://stackoverflow.com/questions/41701601
更新时间:2023-07-18 11:07

最满意答案

你可以这样做

    //seek_bar.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
    android:id="@android:id/background"
    android:drawable="@drawable/seek_bar_background"/>
<item android:id="@android:id/progress"
    android:drawable="@drawable/seek_bar_progress" />
</layer-list>

//seek_bar_background.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

<gradient
    android:angle="270"
    android:startColor="#8a8c8f"
    android:endColor="#58595b" />

<corners android:radius="5dip" />

</shape>

//seek_bar_progress.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
    android:id="@android:id/background"
    android:drawable="@drawable/seek_bar_background"/>
<item android:id="@android:id/progress">
    <clip android:drawable="@drawable/seek_bar_progress_fill" />
</item>

</layer-list>

//seek_bar_progress_fill.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

<gradient
    android:startColor="#b3d27e"       
    android:endColor="#93c044"
    android:angle="270"
 />
 <corners android:radius="5dip" />  

</shape>

参考链接


you can do it like this

    //seek_bar.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
    android:id="@android:id/background"
    android:drawable="@drawable/seek_bar_background"/>
<item android:id="@android:id/progress"
    android:drawable="@drawable/seek_bar_progress" />
</layer-list>

//seek_bar_background.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

<gradient
    android:angle="270"
    android:startColor="#8a8c8f"
    android:endColor="#58595b" />

<corners android:radius="5dip" />

</shape>

//seek_bar_progress.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
    android:id="@android:id/background"
    android:drawable="@drawable/seek_bar_background"/>
<item android:id="@android:id/progress">
    <clip android:drawable="@drawable/seek_bar_progress_fill" />
</item>

</layer-list>

//seek_bar_progress_fill.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

<gradient
    android:startColor="#b3d27e"       
    android:endColor="#93c044"
    android:angle="270"
 />
 <corners android:radius="5dip" />  

</shape>

Ref link

相关问答

更多
  • 你甚至可以在没有使用图像的情况下获得圆角渐变按钮。 ...
  • 是的,你可以,但这是一个痛苦的屁股 。 但你可以使用SVG文件(你需要第三方库,比如android-svg )。 或者您可以使用Unicode 字符 ,因为根据定义,TTF字体是矢量的。 并非所有字形都受Android标准字体支持,因此您可能希望使用免费的专用图标字体 ,例如FontAwesome [编辑] 马克要求它,所以...... 好的,这家伙通过XML显示了一种棘手的箭头形状: http://looksok.wordpress.com/2013/08/24/android-triangle-arro ...
  • 好吧,这真的很简单。 这是vala代码: private void draw_rounded_path(Context ctx, double x, double y, double width, double height, double radius) { double degrees = M_PI / 180.0; ctx.new_sub_path(); ctx.arc(x + width - radius, y + radius, radius, -90 * de ...
  • 尝试使用px而不是dp: 编辑: 这是我用来在我的一个元素中舍入边缘的完整XML:
  • 使用标签创建带有圆角的XML的drawable。 (您可以使用形状标签做其他内容,如定义颜色渐变)。 这是我在我的一个应用程序中使用的XML文件的副本,以创建具有白色背景,黑色边框和圆角的drawable:
  • 所以在这里发布这个问题。 我修改了,发现了我的错误。 所以在这里。 在我的category_item_selector.xml中,我将背景设置为@drawable/controlbar_gradient ,定义为
  • 我找到了解决方案 @TargetApi(Build.VERSION_CODES.LOLLIPOP) public static Drawable getAttrDrawable(Context context, @AttrRes int attrRes) { Drawable drawable = null; TypedValue value = new TypedValue(); if (context.getTheme().resolveAttribute(attrRes, va ...
  • 我找到了解决方案: 1)在res/values/创建主题XML: